I am currently working on an android library in android studio 3.0.1 with cpp support. Therefor I started with a little test to check the functionality and get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no native-lib in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.pmdtec.testproject.TestClass.<clinit>(TestClass.java:6)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:107)
My Source Files are:
TestProject/app/src/java/com/example/TestClass.java
package com.example;
public class TestClass
{
static {
System.loadLibrary("native-lib");
}
public static void main(String[] args)
{
new TestClass().helloNative();
}
native void helloNative();
}
TestProject/app/src/cpp/native-lib.cpp
#include <jni.h>
extern "C"
JNIEXPORT void JNICALL
Java_com_example_TestClass_helloNative(JNIEnv *env, jobject instance)
{
// implement later
}
And I also added "android.enableAapt2=false" to the TestProject/gradle.properties because the gradle build got this error (This error does not occure anymore. I just wanted to document that, and why I added the property to gradle.properties)
Information:Gradle: Executing tasks: [:app:assembleDebug]
Information:Gradle: BUILD FAILED in 4s
Information:15.01.2018 11:46 - Compilation completed with 5 errors and 0 warnings in 6s 736ms
Error:Gradle: failed to create directory 'D:\workspace\TestProject\app\build\generated\source\r\debug\com\example'.
Error:Gradle: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Gradle: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Gradle: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Gradle: Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
The files that are not shown here are the generated files. So my question is, does anyone know why I get the error mentiont at the top of this post?
Some more details:
The resulting .apk contains the following files
/lib/arm64-v8a/libnative-lib.so
/lib/armeabi-v7a/libnative-lib.so
/lib/x86/libnative-lib.so
/lib/x86_64/libnative-lib.so
/META-INF/...
/res/...
AndroidManifest.xml
classes.dex
resources.arsc
Is there anything I have to do, so the native-lib is linked?
Many thanks in advance for your support!
Kind regards Robert A. Fritsch