javaandroidandroid-ndkshared-librariesgradle-experimental

Android Studio: generating .so files using experimental plugin


I have a project in AS with native library. I'm trying to use experimental plugin (gradle-experimental:0.6.0-alpha5) to get .so files (to use it later in System.loadLibrary (). But I can't generate them. And I really can't understand, why?

I've used this instruction to write my build.gradle. Here is it:

apply plugin: "com.android.model.application"
model {  
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.camera.simplewebcam"
    minSdkVersion.apiLevel 15
    targetSdkVersion.apiLevel 22

    buildConfigFields {
        create() {
            type "int"
            name "VALUE"
            value "1"
        }
    }

    ndk {
        moduleName "ImageProc"
    }
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles.add(file("proguard-rules.pro"))
    }
}

// Configures source set directory.
sources {
    main {
        jni {
          source {
                srcDir "src/main"
            }
        }
    }
}
productFlavors {
    create("arm") {
        ndk {   
            abiFilters.add("armeabi-v7a")
        }
    }
    create("fat") {           
    }

}
}


dependencies {
    compile fileTree(dir: "lib", include: ['.jar','.so'])
    compile "com.android.support:appcompat-v7:23.+"
}

The error I get when try to run the application:

java.lang.UnsatisfiedLinkError: Couldn't load ImageProc from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.camera.simplewebcam-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.camera.simplewebcam-1, /vendor/lib, /system/lib, /system/lib/arm]]]: findLibrary returned null

Here is my project's structure: enter image description here

Here is my Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := ImageProc
LOCAL_SRC_FILES := ImageProc.c
LOCAL_LDLIBS    := -llog -ljnigraphics

include $(BUILD_SHARED_LIBRARY)

Here is my Application.mk:

# The ARMv7 is significanly faster due to the use of the hardware FPU
APP_ABI := armeabi armeabi-v7a
APP_PLATFORM := android-8

Where is my error?


Solution

  • Problem is here targetSdkVersion.apiLevel 22

    An integer designating the API Level that the application targets. If not set, the default value equals that given to minSdkVersion. This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).

    Do

    targetSdkVersion.apiLevel 23
    

    and you should use

    compile "com.android.support:appcompat-v7:23.0.1