android / ndk-samples

Android NDK samples with Android Studio
http://developer.android.com/ndk
Apache License 2.0
9.97k stars 4.15k forks source link

fix native-activity ClassNotFoundException #998

Closed heyoukang closed 2 months ago

heyoukang commented 2 months ago

fix issue https://github.com/android/ndk-samples/issues/929

why? Library 'androidx.appcompat:appcompat:1.5.1' merged 'InitializationProvider' to final AndroidManifest.xml,and it also add InitializationProvider.class to final apk. but android:hasCode="false" make this apk is pure native apk, so InitializationProvider.class doesn't work. we can clearly see the crash info DexPathList is empty.

Didn't find class "androidx.startup.InitializationProvider" on path: DexPathList[[],nativeLibraryDirectories

so AndroidManifest.xml has InitializationProvider info, but dex doesn't. that's why we get ClassNotFoundException.

there are two solutions.

remove useless library 'androidx.appcompat:appcompat:1.5.1', Neither AndroidManifest.xml nor dex have InitializationProvider info remove android:hasCode="false", make dex work well this pr remove useless library, and also remove android:hasCode="false" to avoid someone stuck in this problem again. this is just sample, so I think it's ok.

heyoukang commented 2 months ago

@DanAlbert hi DanAlbert, Can you help me merge this pr?

DanAlbert commented 2 months ago

https://github.com/android/ndk-samples/pull/1000 is pretty much the same but includes docs and purges the jar dependencies (of which there are none currently, but it's just another booby trap waiting for someone). Closing this in favor of that PR. Thanks for the help in figuring it out 👍