我正試圖在我的項目中實現hello-jni
sample 。我有Gradle
2.8和'com.android.tools.build:gradle-experimental:0.4.0'
和使用Android Studio 2.0 Preview 3b
。Hello-jni示例在Android Studio 2.0 Preview中不起作用
這是我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
文件夾hello-jni.h
創建:
在我的代碼中的一些部分我導入此:
static {
System.loadLibrary("hello-jni");
}
public static native int testMethod();
並通過自動com pletion創建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
但它不工作。它是全紅:
是什麼問題呢?如何解決它?
哦,這不是問題,我把佔位符放在一個地方,忘了把它放在另一個地方。這是一致的,我有問題'#include' –
它找不到這個庫 –
ndk.dir = C \:\\ Users \\ Filip \\ AppData \\ Local \\ Android \\ sdk \\ ndk-bundle 是的 –