已经有一段时间我向StackOverFlow发布了一个问题。 我想描述我有什么问题,我试过什么...尽可能详细,因为我投票减去上次没有提供详细信息我发布了一个问题。如果有任何我缺乏提供的信息或您需要解决问题的信息,请随时在下面发表评论,以便我可以提供必要的信息来解决此问题。无法解析仅在Windows操作系统中显示的相应JNI函数
本地方法被高亮显示的红色和说 “我有问题”, “无法解析对应JNI功能Java_com_example_〜”
[图像如下附]
当我运行的应用程序,它完美的作品。
警告红色标志仅在Windows操作系统中显示,不在Mac OS中显示。
我正在使用Android Studio 2.3的最新稳定版本。
“我曾尝试”
一些评论建议把externalNativeBuild {...}在gradle这个,因为IDE不拿起正确的。
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
我在Mac OS中进行测试,并警告标志消失了,但它能在Windows OS,这是我在我的公司使用的OS不。 我确定我拥有相同的源代码,并且我还导入了在Mac OS中测试的项目。仍然显示警告标志。
我知道一些人建议只是Simply Ignore JNI Function但是,我不想简单地忽略警告标志,因为后来我需要移植已经移植了库的第三方项目,并包含很多我需要查看的本机方法如果他们每个人都正确链接。
有没有人曾经面对同样的问题,我已经解决了这个问题?
[源代码]
MainActivity
package com.example.sonic.jniexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView textView;
Button button;
HelloNDK helloNDK = new HelloNDK();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView)findViewById(R.id.textview);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textView.setText(helloNDK.stringFromJNI());
}
});
}
}
HelloNDK
package com.example.sonic.jniexample;
public class HelloNDK {
static {
System.loadLibrary("hello-jni");
}
public native String stringFromJNI();
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_CFLAGS += -std=c++14
LOCAL_SRC_FILES := hello-jni.cpp
include $(BUILD_SHARED_LIBRARY)
应用。MK
APP_MODULES := hello-jni
APP_ABI := all
com_example_sonic_jniexample_HelloNDK.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_example_sonic_jniexample_HelloNDK */
#ifndef _Included_com_example_sonic_jniexample_HelloNDK
#define _Included_com_example_sonic_jniexample_HelloNDK
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_example_sonic_jniexample_HelloNDK
* Method: stringFromJNI
* Signature:()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_example_sonic_jniexample_HelloNDK_stringFromJNI
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
HelloNDK.cpp
#include <com_example_sonic_jniexample_HelloNDK.h>
JNIEXPORT jstring JNICALL
Java_com_example_sonic_jniexample_HelloNDK_stringFromJNI(JNIEnv *env,jobject obj) {
jstring str = (*env).NewStringUTF("From JNI");
return str;
}
的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.example.sonic.jniexample"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
moduleName "hello-jni"
}
sourceSets.main {
jni.srcDirs = [] // This prevents the auto generation of Android.mk
jniLibs.srcDir 'src/main/libs'
}
}
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
仍在进行中的问题...我真的不知道为什么会这样。 –