android / ndk-samples

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

Getting ClassNotFoundException on while running Native Activity[NDK] sample app #934

Closed Laxmaandroid closed 5 months ago

Laxmaandroid commented 1 year ago

Steps to Reproduce:

  1. Open android studio
  2. Import sample app named, Native Activity under NDK category
  3. Select any device and run the app in it

Actual:

I saw below exception while deploying the app

Screenshot from 2023-03-23 14-29-32

FATAL EXCEPTION: main Process: com.example.native_activity, PID: 30149 java.lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider: java.lang.ClassNotFoundException: Didn't find class "androidx.startup.InitializationProvider" on path: DexPathList[[],nativeLibraryDirectories=[/data/app/DnDZG8k__rEJWZz3bJMAzA==/com.example.native_activity-n6Xs1BfFs5pShMl0smhnEw==/lib/arm64, /data/app/DnDZG8krEJWZz3bJMAzA==/com.example.native_activity-n6Xs1BfFs5pShMl0smhnEw==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]] at Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.startup.InitializationProvider" on path: DexPathList[[],nativeLibraryDirectories=[/data/app/~~DnDZG8krEJWZz3bJMAzA==/com.example.native_activity-n6Xs1BfFs5pShMl0smhnEw==/lib/arm64, /data/app/~~DnDZG8k__rEJWZz3bJMAzA==/com.example.native_activity-n6Xs1BfFs5pShMl0smhnEw==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:147) at android.app.ActivityThread.installProvider(ActivityThread.java:8296)

BenShen98 commented 1 year ago

I am also getting the same issue.

With Android Studio Electric Eel | 2022.1.1 Patch 2 and commit eb8c57aaf8e4e8da8debfe7a6f44149630ac775e (main branch)

BenShen98 commented 1 year ago

FIY https://github.com/android/ndk-samples/issues/929#issuecomment-1423506761 provides a soultion to this.

diff --git a/native-activity/app/src/main/AndroidManifest.xml b/native-activity/app/src/main/AndroidManifest.xml
index 8698411..0b3175c 100644
--- a/native-activity/app/src/main/AndroidManifest.xml
+++ b/native-activity/app/src/main/AndroidManifest.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- BEGIN_INCLUDE(manifest) -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
     android:versionCode="1"
           android:versionName="1.0">

@@ -12,6 +13,10 @@
       android:label="@string/app_name"
       android:hasCode="false">

+    <provider android:name="androidx.startup.InitializationProvider"
+        android:authorities="${applicationId}.androidx-startup"
+        tools:node="remove" />
+
     <!-- Our activity is the built-in NativeActivity framework class.
          This will take care of integrating with our NDK code. -->
     <activity android:name="android.app.NativeActivity"
554512097 commented 1 year ago

yes!

dingsijie-nreal commented 9 months ago

same here, BenShen98's reply works for me. Though the link#929 (comment) seems broken...

FIY #929 (comment) provides a soultion to this.

diff --git a/native-activity/app/src/main/AndroidManifest.xml b/native-activity/app/src/main/AndroidManifest.xml
index 8698411..0b3175c 100644
--- a/native-activity/app/src/main/AndroidManifest.xml
+++ b/native-activity/app/src/main/AndroidManifest.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- BEGIN_INCLUDE(manifest) -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
     android:versionCode="1"
           android:versionName="1.0">

@@ -12,6 +13,10 @@
       android:label="@string/app_name"
       android:hasCode="false">

+    <provider android:name="androidx.startup.InitializationProvider"
+        android:authorities="${applicationId}.androidx-startup"
+        tools:node="remove" />
+
     <!-- Our activity is the built-in NativeActivity framework class.
          This will take care of integrating with our NDK code. -->
     <activity android:name="android.app.NativeActivity"
DanAlbert commented 5 months ago

Duplicate of #929