Android Studio:使用实验性插件生成 .so 文件
Android Studio: generating .so files using experimental plugin
我在 AS 中有一个带有本机库的项目。我正在尝试使用实验性插件 (gradle-experimental:0.6.0-alpha5) 来获取 .so 文件(稍后在 System.loadLibrary () 中使用它)。但我无法生成它们。而且我真的不明白,为什么?
我用这个 instruction 写了我的 build.gradle。在这里:
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.+"
}
我尝试 运行 应用程序时遇到的错误:
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
这是我的项目结构:
这是我的 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)
这是我的 Application.mk:
# The ARMv7 is significanly faster due to the use of the hardware FPU
APP_ABI := armeabi armeabi-v7a
APP_PLATFORM := android-8
我的错误在哪里?
问题出在这里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).
做
targetSdkVersion.apiLevel 23
你应该使用
compile "com.android.support:appcompat-v7:23.0.1
我在 AS 中有一个带有本机库的项目。我正在尝试使用实验性插件 (gradle-experimental:0.6.0-alpha5) 来获取 .so 文件(稍后在 System.loadLibrary () 中使用它)。但我无法生成它们。而且我真的不明白,为什么?
我用这个 instruction 写了我的 build.gradle。在这里:
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.+"
}
我尝试 运行 应用程序时遇到的错误:
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
这是我的项目结构:
这是我的 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)
这是我的 Application.mk:
# The ARMv7 is significanly faster due to the use of the hardware FPU
APP_ABI := armeabi armeabi-v7a
APP_PLATFORM := android-8
我的错误在哪里?
问题出在这里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).
做
targetSdkVersion.apiLevel 23
你应该使用
compile "com.android.support:appcompat-v7:23.0.1