Я получаю SIGABORT при вызове GetDoubleField ().
Я написал небольшую примерную программу, чтобы показать проблему ...
MainActivity. java
package net.directionalsystems.jnitest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
// Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("native-lib");
}
private static final String TAG = "Mainactivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Example of a call to a native method
TextView tv = findViewById(R.id.sample_text);
JniComms jc = new JniComms();
jc.latitude = 10;
jc.logitude = 20;
jc.txtLocation = "Hello";
try {
tv.setText(stringFromJNI(jc));
}
catch (Exception e)
{
Log.e(TAG, "onCreate: ", e);
}
}
/**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
public native String stringFromJNI(JniComms jc);
}
JniComms. java
package net.directionalsystems.jnitest;
import java.util.ArrayList;
public class JniComms
{
public double latitude;
public double logitude;
public String txtLocation;
//public ArrayList<BleStatus> bleStatusArray;
}
native-lib. cpp
#include <jni.h>
#include <string>
extern "C" JNIEXPORT jstring JNICALL
Java_net_directionalsystems_jnitest_MainActivity_stringFromJNI(
JNIEnv *env,
jobject jo,
jobject jc)
{
jclass jcClass = env->GetObjectClass(jc);
jfieldID iId = env->GetFieldID(jcClass, "latitude", "D");
// Executing the next line causes SIGABORT
jdouble latitude = env->GetDoubleField(jcClass, iId);
std::string hello = "Hello world";
return env->NewStringUTF(hello.c_str());
}
Сборка Файл .gradle следует ...
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "net.directionalsystems.jnitest"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
customDebugType {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
debuggable true
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
Это должно быть что-то простое и глупое, что я делаю.
Я хотел бы выполнить отладку в коде NDK, но все, что я получаю, это отображаемый файл jni.h, который не может войти в сам код JNI. Наличие такой возможности может дать мне представление о том, что не так.
Большое спасибо за любую помощь.
С уважением, Джек ie