Android java.lang.IllegalArgumentException: unable to find native library: main
I found several projects today that demonstrate Android ndk programming. This project
I am trying to start a DroidBlaster project . I have compiled all native libraries without error. Here's the result:
I made a few small changes:
1). Added tag application
to AndroidManifest.xml
variantandroid:hasCode="true"
2). I expanded from my own activity and loaded all libraries into a block static
.
I did this because without these changes, Android cannot find the library libdroidblaster.so
that was declared in AndroidManifest.xml
(Here is the code from the author) :
<activity
android:name="android.app.NativeActivity"
android:label="@string/app_name" >
<meta-data
android:name="android.app.lib_name"
android:value="droidblaster" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Mine now AndroidManifest.xml
looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.demo.droidblaster"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="22" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:hasCode="true">
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="android.app.NativeActivity"
android:label="@string/app_name" >
<meta-data
android:name="android.app.lib_name"
android:value="droidblaster" />
</activity>
</application>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
</manifest>
And my new activity :
public class MainActivity extends NativeActivity {
static {
System.loadLibrary("irrlicht");
System.loadLibrary("droidblaster");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
When I try to run the application, I get this error:
06-05 12: 56: 26.523 11528-11528 / com.demo.droidblaster E / AndroidRuntime: FATAL EXCEPTION: main Process: com.demo.droidblaster, PID: 11528 java.lang.RuntimeException: Unable to start Activity ComponentInfo {com. demo.droidblaster / com.demo.droidblaster.MainActivity}: java.lang.IllegalArgumentException: Unable to find native library: main at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2658) at android.app.ActivityThread.handleLaunchActivity (ActivityThread .java: 2723) at android.app.ActivityThread.access $ 900 (ActivityThread.java:172) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1422) on android.os.Handler.dispatchMessage (Handler.java : 102) at android.os.Looper.loop (Looper.java:145) at android.app.ActivityThread.main (ActivityThread.java:5832) at java.lang.reflect.Method.invoke (native method) at java.lang.reflect.Method.invoke (Method.java:372) at com.android.internal.os. ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1194) Caused by: java.lang.IllegalArgumentException: Cannot find native library: main in android.app. NativeActivity.onCreate (NativeActivity.java:170) at com.demo.droidblaster.MainActivity.onCreate (MainActivity.java:17) at android.app.Activity.performCreate (Activity.java:6221) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2611) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2723) at android.app.ActivityThread.access $ 900 (ActivityThread.java:172) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1422) on android.os. Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:145) at android.app.ActivityThread.main (ActivityThread.java:5832) at java.lang.reflect.Method.invoke (native method) at java.lang.reflect.Method.invoke (Method.java:372) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1399) at com.android.internal.os .ZygoteInit.main (ZygoteInit.java:1194)dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:145) at android.app.ActivityThread.main (ActivityThread.java:5832) at java.lang.reflect.Method.invoke (native method) in java.lang.reflect.Method.invoke (Method.java:372) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit .main (ZygoteInit.java:1194)dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:145) at android.app.ActivityThread.main (ActivityThread.java:5832) at java.lang.reflect.Method.invoke (native method) in java.lang.reflect.Method.invoke (Method.java:372) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit .main (ZygoteInit.java:1194)
So the reason is this:
java.lang.IllegalArgumentException: Unable to find native library: main
I cannot find a solution to solve this problem.
Does anyone know how to fix this?
source to share
.so
files are not automatically included in Android Studio. Follow the answers given here to enable them: fooobar.com/questions/12706 / ...
source to share
You can try installing new gradle with ndk support integration (experemental). http://ph0b.com/new-android-studio-ndk-support/#more-236 There will be an android.ndk field (in your gradle.build) where you have to add native_android_glue:
android.ndk {
moduleName = "droidblaster"
CFlags.add("-I${file("src/main/jni/android_native_app_glue")}".toString())
ldLibs.addAll(["log", "android", "EGL", "GLESv1_CM"])
}
source to share