ndk-samples icon indicating copy to clipboard operation
ndk-samples copied to clipboard

I can't run the sample ndk-samples/tree/main/native-activity

Open gmmo opened this issue 2 years ago • 5 comments

Hi, I need to understand how to handle touch events from the NDK side.

I downloaded the sample and it compiled. But when it is time to run, it always throws an exception as below:

2023-08-19 20:29:03.049 4184-4184/com.example.native_activity E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.native_activity, PID: 4184
    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/~~v0-30k3yjJ2MXvxZsN7zpA==/com.example.native_activity-fd7x7SgtJ4KPBqGilTLNpA==/lib/arm64, /data/app/~~v0-30k3yjJ2MXvxZsN7zpA==/com.example.native_activity-fd7x7SgtJ4KPBqGilTLNpA==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]]
        at android.app.ActivityThread.installProvider(ActivityThread.java:7769)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:7275)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6982)
        at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2236)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:205)
        at android.os.Looper.loop(Looper.java:294)
        at android.app.ActivityThread.main(ActivityThread.java:8176)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.startup.InitializationProvider" on path: DexPathList[[],nativeLibraryDirectories=[/data/app/~~v0-30k3yjJ2MXvxZsN7zpA==/com.example.native_activity-fd7x7SgtJ4KPBqGilTLNpA==/lib/arm64, /data/app/~~v0-30k3yjJ2MXvxZsN7zpA==/com.example.native_activity-fd7x7SgtJ4KPBqGilTLNpA==/base.apk!/lib/arm64-v8a, /system/lib64, /system/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:7753)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:7275) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6982) 
        at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2236) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loopOnce(Looper.java:205) 
        at android.os.Looper.loop(Looper.java:294) 
        at android.app.ActivityThread.main(ActivityThread.java:8176) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) 

I am running on Windows and my android studio version is:

Android Studio Electric Eel | 2022.1.1 Patch 2 Build #AI-221.6008.13.2211.9619390, built on February 16, 2023 Runtime version: 11.0.15+0-b2043.56-9505619 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 11 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 1792M Cores: 16 Registry: external.system.auto.import.disabled=true ide.text.editor.with.preview.show.floating.toolbar=false cidr.max.intellisense.file.length=1000000

Non-Bundled Plugins: com.intellij.plugins.visualstudiokeymap (221.6008.15) GLSL (1.21)

The device is Samsung Galaxy.

any clues how to run this?

gmmo avatar Sep 06 '23 05:09 gmmo

I have a same question, did you resolve it?

JChunyu avatar Sep 06 '23 06:09 JChunyu

No, I need to get these touch events working on NDK, but I can't do it without a sample. Do you know how to resolve this?

gmmo avatar Sep 06 '23 16:09 gmmo

@gmmo I don't know why, but it works if I try to remove android:hasCode="false" in AndroidManifest.xml file. And I found that android:hasCode="false" means telling system that doesn't try to load any application code(refer from here). And in tutorial here which also says that we need to use android:hasCode="false"

Intro1997 avatar Sep 27 '23 08:09 Intro1997

@Intro1997 it works with your path thx! I owe you cookies :) This is an important sample, I can't believe google leave it like that out of the box. @JChunyu check out @Intro1997 work around.

gmmo avatar Sep 27 '23 16:09 gmmo

@Intro1997 it works with your path thx! I owe you cookies :) This is an important sample, I can't believe google leave it like that out of the box. @JChunyu check out @Intro1997 work around.

I'm glad this helped you!

Intro1997 avatar Sep 28 '23 12:09 Intro1997

Duplicate of #929

DanAlbert avatar May 03 '24 21:05 DanAlbert