5

I'm quite new to Android native development and lately experimenting with building directly from CLI without Android Studio (really don't like the IDE and find Gradle overly complex, although I can't get my toolchain running yet...)

Using guidance from around the web, particularly this, I have a extremely basic app which successfully builds to a signed and aligned APK (as far as I can tell). I am building against platform 14 with Java 1.8 and I observed no changes when altering this configuration.

I've put the app source on GitHub for reference for this question. It's one activity with one layout.

When it comes to adb install (or manually install from the device), installation always fails with INSTALL_FAILED_INVALID_APK... Package /data/app/net.ilmiont.helloworld-...==/base.apk code is missing (... is some long ID by appearances).

Logcat

Running adb logcat during the installation attempt, I get this:

11-16 10:34:52.729 24742 7402 I Finsky : [9791] com.google.android.finsky.verifier.impl.ea.a(82): Skipping verification. Disabled by user setting 11-16 10:34:52.729 24742 7402 I Finsky : [9791] com.google.android.finsky.verifier.impl.ea.a(43): Skipping anti malware verification due to pre-check failure 11-16 10:34:52.730 24742 24742 I Finsky : [2] com.google.android.finsky.verifier.impl.fs.c(164): Verifying id=132, result=1 11-16 10:34:52.735 24742 24742 I Finsky : [2] com.google.android.finsky.verifier.impl.fs.c(177): Verification complete: id=132, package_name=net.ilmiont.helloworld 11-16 10:34:52.752 1856 27782 E : Couldn't opendir /data/data/net.ilmiont.helloworld: No such file or directory 11-16 10:34:52.753 1856 27782 E installd: Failed to delete /data/data/net.ilmiont.helloworld: No such file or directory 11-16 10:34:52.753 1856 27782 E : Couldn't opendir /data/user_de/0/net.ilmiont.helloworld: No such file or directory 11-16 10:34:52.753 1856 27782 E installd: Failed to delete /data/user_de/0/net.ilmiont.helloworld: No such file or directory 11-16 10:34:52.754 2198 2398 W PackageManager: com.android.server.pm.Installer$InstallerException: android.os.ServiceSpecificException: Failed to delete /data/user_de/0/net.ilmiont.helloworld (code 2) 11-16 10:34:52.756 2198 2398 W PackageManager: Package couldn't be installed in /data/app/net.ilmiont.helloworld-pbDVHiVe6mEghhiOqRUNjg== 11-16 10:34:52.756 2198 2398 W PackageManager: com.android.server.pm.PackageManagerException: Package /data/app/net.ilmiont.helloworld-pbDVHiVe6mEghhiOqRUNjg==/base.apk code is missing

I do not understand why it is trying to open/delete these directories when the app is just getting installed (and has not ever successfully installed) --- I don't know enough about Android internals, but from that trace it does look like the deletion is the problem.

I've looked over my source multiple times and just can't see what I'm missing. The manifest looks OK, the layout looks OK, the Java is all of two lines. So what am I missing? It must be something glaringly obvious.

The device

This may be relevant, so here are all the details.

Nokia 6 (original one) running unrooted Android 8.1.

I opened Android Studio, created the default boilerplate app and hit "Run", and it built and deployed successfully, so clearly there is something wrong with my app/build toolchain which is making this break, and I've out of ideas of where to look.

The build script (excerpts, it does build but will not deploy)

aapt package -v -f -m -J $PROJECT_SOURCE -M $ANDROID_MANIFEST -S $ANDROID_RESOURCES -I $ANDROID_SDK/platforms/android-$ANDROID_API/android.jar;

javac -d $JAVA_COMPILE_DESTINATION -source $JAVA_VERSION -target $JAVA_VERSION_TARGET -classpath "$PROJECT_SOURCE$JAVA_CLASSPATH_LIBS" -bootclasspath $ANDROID_SDK/platforms/android-$ANDROID_API/android.jar $PROJECT_SOURCE/$PROJECT_PACKAGE_SOURCE/*.java;

dx --dex --output=$DX_COMPILE_DESTINATION $JAVA_COMPILE_DESTINATION;

aapt package -f -m -F $APP_APK_UNALIGNED -M $ANDROID_MANIFEST -S $ANDROID_RESOURCES -I $ANDROID_SDK/platforms/android-$ANDROID_API/android.jar;

aapt add $APP_APK_UNALIGNED $DX_COMPILE_DESTINATION;

zipalign -f 4 $APP_APK_UNALIGNED $APP_APK;

apksigner sign --ks /home/jh_walker/.keystore $APP_APK;

Keystore

keytool -genkeypair -validity 365 -keystore $KEYSTORE -alias $KEYSTORE_ALIAS -sigalg SHA1withDSA -keyalg DSA -keysize 1024

What I've tried

  • Java 1.7/1.8
  • Compiling against different Android platforms (21/28)
  • Including additional assets (didn't have icons originally)
  • Setting use-sdk in the manifest (no impact)

What am I missing?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ilmiont
  • 2,032
  • 4
  • 27
  • 44

3 Answers3

2

I got there.

aapt inspect app.apk

And immediately I noticed in the APK, was ./bin/classes.dex, and none of the other files had that ./ prefix.

Digging deeper, and I saw in my build script I was compiling DEX to ./bin/classes.dex, and then adding that path to my APK. But it appears something about that path wasn't liked by aapt (although it's entirely valid for where I was running it from), and it didn't properly add the file --- it seems just some empty ./bin/classes.dex it made up.

(Yes that's a kinda pathetic explanation, and I'll investigate properly later!)

Anyway, it seems you have to add from your current directory: classes.dex. Maybe this is obvious to someone more familiar with the tools.

Anyway,

cp ./bin/classes.dex . && aapt add app.apk.unaligned classes.dex works, but aapt add app.apk.unaligned ./bin/classes.dex does not .

Ilmiont
  • 2,032
  • 4
  • 27
  • 44
0

If this somehow happens to you when you want to install a debug (gradle installDebug) version of your App in your device, check that versionCode and versionName are not changed from the last release published to the Play Store.

0

I was also getting the base.apk code is missing error message when attempting to install the apk on my device. In my case, I had recently upgraded Gradle and Android Gradle tools (naively because Studio recommended it).... So, downgrading to the previous gradle and tools version fixed it for me.

Downgrading can be done by editing the version numbers in 2 locations: android/build.gradle and gradle-wrapper.properties - and then doing a gradle sync in Android Studio.

enerve
  • 63
  • 6