我正在尝试实施hello-jni sample https://github.com/googlesamples/android-ndk/tree/master/hello-jni进入我的项目。我有Gradle
2.8 和'com.android.tools.build:gradle-experimental:0.4.0'
并使用Android Studio 2.0 Preview 3b
.
这是我的build.gradle
:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "lala.lala"
minSdkVersion.apiLevel = 16
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
}
}
/*
* native build settings
*/
android.ndk {
moduleName = "hello-jni"
// cppFlags.add("-fno-rtti")
// cppFlags.add("-fno-exceptions")
// ldLibs.addAll(["android", "log"])
// stl = "system"
}
android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" @
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm") {
ndk.abiFilters.add("armeabi")
}
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
create("arm8") {
ndk.abiFilters.add("arm64-v8a")
}
create("x86") {
ndk.abiFilters.add("x86")
}
create("x86-64") {
ndk.abiFilters.add("x86_64")
}
create("mips") {
ndk.abiFilters.add("mips")
}
create("mips-64") {
ndk.abiFilters.add("mips64")
}
// To include all cpu architectures, leaves abiFilters empty
create("all")
}
android.buildTypes {
release {
minifyEnabled = false
//proguardFiles.add(file('proguard-rules.txt'))
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.google.android.gms:play-services-ads:8.3.0'
compile 'com.google.android.gms:play-services-analytics:8.3.0'
compile 'com.google.android.gms:play-services-appindexing:8.3.0'
}
我已经创建了JNI
folder hello-jni.h
:
在我的代码的某些部分我导入了这个:
static {
System.loadLibrary("hello-jni");
}
public static native int testMethod();
并通过自动完成创建hello-jni.c
:
#include "hello-jni.h"
JNIEXPORT jintJNICALL
Java_lala_lala_HomeScreen_testMethod(JNIEnv
*env,
jclass type
)
{
// TODO
}
头文件hello-jni.h
:
//
// Created by Filip on 15.12.2015..
//
#ifndef PHOTO_HELLO_JNI_H
#define PHOTO_HELLO_JNI_H
#endif //PHOTO_HELLO_JNI_H
但这不起作用。它是全红色的:
什么是问题?怎么解决呢?
要使示例正常工作,您可以尝试以下步骤:
- 的签名
jni
method Java_filsoft_photo_HomeScreen_testMethod(...)
与您的包名称不匹配lala.lala
。对于要调用的方法,使其签名与包名一致。
-
尝试编辑hello-jni.c
如下:
#include <jni.h>
#include "hello-jni.h"
jint Java_lala_lala_HomeScreen_testMethod( JNIEnv* env, jclass type )
{
}
-
关于红色突出显示,截至Android Studio 2.0 Preview 3b
the NDK
该功能尚未得到正式支持,据我猜测,这就是其原因。禁用Android NDK support
插件(如果已安装)
Settings
> Plugins
> 取消选中Android NDK support
> 重新启动Android Studio
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)