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?