Discussion:
Creating JVM using JNI functions
(too old to reply)
Ilya Berezhnoy
2018-07-20 11:00:36 UTC
Permalink
Hi everyone,

I try to find out is it possible to create jvm machine to call java code in
native application (c++).
In my project i use gradle and cmake for building.

here is a part of configuration

android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mycomp.vpntuner"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
cppFlags "-std=c++14 -fexceptions"
}
}

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}


and a function to create VM:

JavaVM* javaVM = NULL;
JNIEnv* jEnv = NULL;

JavaVMOption opt[1];
opt[0].optionString = "-Djava.class.path=./";
JavaVMInitArgs args;
args.version = JNI_VERSION_1_6;
args.options = opt;
args.nOptions = 1;
args.ignoreUnrecognized = JNI_FALSE;

void *libdvm_dso = dlopen("libart.so", RTLD_NOW);
if(!libdvm_dso )
{
printf("error to load libart.so library\n");
return 1;
}
void *libandroid_runtime_dso = dlopen("libandroid_runtime.so", RTLD_NOW);
if(!libandroid_runtime_dso)
{
printf("error to load libandroid_runtime.so library\n");
return 1;
}
JNI_CreateJavaVM_t JNI_CreateJavaVM = NULL;
JNI_CreateJavaVM = (JNI_CreateJavaVM_t) dlsym(libdvm_dso, "JNI_CreateJavaVM");
if(!JNI_CreateJavaVM)
{
printf("error: JNI_CreateJavaVM is not found\n");
return 2;
}
printf("JNI_CreateJavaVM is linked!\n");
// registerNatives_t registerNatives;
// registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "Java_com_android_internal_util_WithFramework_registerNatives");
// if(!registerNatives)
// {
// printf("error: registerNatives is not found\n");
// return 3;
// }
// printf("registerNatives is linked!\n");
int rv = JNI_CreateJavaVM(&javaVM, &jEnv, &args);
if (rv < 0)
{
printf("Unable to Launch JVM %d\n", rv);
return 4;
}
printf("jvm is running!\n");

// if(!registerNatives(*p_env, 0))
// {
// printf("error to register natives\n");
// return 5;
// }
// printf("env is reg!\n");

so, the app is fault when JNI_CreateJavaVM is calling with SIGABRT signal.
I will be grateful for any help!
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Philippe Simons
2018-07-20 16:29:16 UTC
Permalink
but but...
why would you want to create a JVM, when you application is already running
in a JVM ?

anyway, I'm pretty sure that's not possible

Philippe
Post by Ilya Berezhnoy
Hi everyone,
I try to find out is it possible to create jvm machine to call java code
in native application (c++).
In my project i use gradle and cmake for building.
here is a part of configuration
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mycomp.vpntuner"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
cppFlags "-std=c++14 -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
JavaVM* javaVM = NULL;
JNIEnv* jEnv = NULL;
JavaVMOption opt[1];
opt[0].optionString = "-Djava.class.path=./";
JavaVMInitArgs args;
args.version = JNI_VERSION_1_6;
args.options = opt;
args.nOptions = 1;
args.ignoreUnrecognized = JNI_FALSE;
void *libdvm_dso = dlopen("libart.so", RTLD_NOW);
if(!libdvm_dso )
{
printf("error to load libart.so library\n");
return 1;
}
void *libandroid_runtime_dso = dlopen("libandroid_runtime.so", RTLD_NOW);
if(!libandroid_runtime_dso)
{
printf("error to load libandroid_runtime.so library\n");
return 1;
}
JNI_CreateJavaVM_t JNI_CreateJavaVM = NULL;
JNI_CreateJavaVM = (JNI_CreateJavaVM_t) dlsym(libdvm_dso, "JNI_CreateJavaVM");
if(!JNI_CreateJavaVM)
{
printf("error: JNI_CreateJavaVM is not found\n");
return 2;
}
printf("JNI_CreateJavaVM is linked!\n");
// registerNatives_t registerNatives;
// registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "Java_com_android_internal_util_WithFramework_registerNatives");
// if(!registerNatives)
// {
// printf("error: registerNatives is not found\n");
// return 3;
// }
// printf("registerNatives is linked!\n");
int rv = JNI_CreateJavaVM(&javaVM, &jEnv, &args);
if (rv < 0)
{
printf("Unable to Launch JVM %d\n", rv);
return 4;
}
printf("jvm is running!\n");
// if(!registerNatives(*p_env, 0))
// {
// printf("error to register natives\n");
// return 5;
// }
// printf("env is reg!\n");
so, the app is fault when JNI_CreateJavaVM is calling with SIGABRT signal.
I will be grateful for any help!
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CADomA487y3ogusmQAo-FwxLBnG-_zNYkDUYw0xMWx70inToysg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Andrew Esh
2018-07-20 17:07:44 UTC
Permalink
Pure native android apps are possible:

https://github.com/googlesamples/android-ndk/tree/master/native-activity
https://developer.android.com/reference/android/app/NativeActivity
Post by Philippe Simons
but but...
why would you want to create a JVM, when you application is already
running in a JVM ?
anyway, I'm pretty sure that's not possible
Philippe
Post by Ilya Berezhnoy
Hi everyone,
I try to find out is it possible to create jvm machine to call java code
in native application (c++).
In my project i use gradle and cmake for building.
here is a part of configuration
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mycomp.vpntuner"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
cppFlags "-std=c++14 -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
JavaVM* javaVM = NULL;
JNIEnv* jEnv = NULL;
JavaVMOption opt[1];
opt[0].optionString = "-Djava.class.path=./";
JavaVMInitArgs args;
args.version = JNI_VERSION_1_6;
args.options = opt;
args.nOptions = 1;
args.ignoreUnrecognized = JNI_FALSE;
void *libdvm_dso = dlopen("libart.so", RTLD_NOW);
if(!libdvm_dso )
{
printf("error to load libart.so library\n");
return 1;
}
void *libandroid_runtime_dso = dlopen("libandroid_runtime.so", RTLD_NOW);
if(!libandroid_runtime_dso)
{
printf("error to load libandroid_runtime.so library\n");
return 1;
}
JNI_CreateJavaVM_t JNI_CreateJavaVM = NULL;
JNI_CreateJavaVM = (JNI_CreateJavaVM_t) dlsym(libdvm_dso, "JNI_CreateJavaVM");
if(!JNI_CreateJavaVM)
{
printf("error: JNI_CreateJavaVM is not found\n");
return 2;
}
printf("JNI_CreateJavaVM is linked!\n");
// registerNatives_t registerNatives;
// registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "Java_com_android_internal_util_WithFramework_registerNatives");
// if(!registerNatives)
// {
// printf("error: registerNatives is not found\n");
// return 3;
// }
// printf("registerNatives is linked!\n");
int rv = JNI_CreateJavaVM(&javaVM, &jEnv, &args);
if (rv < 0)
{
printf("Unable to Launch JVM %d\n", rv);
return 4;
}
printf("jvm is running!\n");
// if(!registerNatives(*p_env, 0))
// {
// printf("error to register natives\n");
// return 5;
// }
// printf("env is reg!\n");
so, the app is fault when JNI_CreateJavaVM is calling with SIGABRT signal.
I will be grateful for any help!
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Dan Albert' via android-ndk
2018-07-20 17:49:02 UTC
Permalink
In which case you should be using native_app_glue. The sample is a little
convoluted, but the JavaVM is available as app->activity->vm (where app is
the android_app struct that is passed to android_main):
https://github.com/googlesamples/android-ndk/blob/master/native-activity/app/src/main/cpp/main.cpp#L273
Post by Andrew Esh
https://github.com/googlesamples/android-ndk/tree/master/native-activity
https://developer.android.com/reference/android/app/NativeActivity
Post by Philippe Simons
but but...
why would you want to create a JVM, when you application is already
running in a JVM ?
anyway, I'm pretty sure that's not possible
Philippe
Post by Ilya Berezhnoy
Hi everyone,
I try to find out is it possible to create jvm machine to call java code
in native application (c++).
In my project i use gradle and cmake for building.
here is a part of configuration
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mycomp.vpntuner"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
cppFlags "-std=c++14 -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
JavaVM* javaVM = NULL;
JNIEnv* jEnv = NULL;
JavaVMOption opt[1];
opt[0].optionString = "-Djava.class.path=./";
JavaVMInitArgs args;
args.version = JNI_VERSION_1_6;
args.options = opt;
args.nOptions = 1;
args.ignoreUnrecognized = JNI_FALSE;
void *libdvm_dso = dlopen("libart.so", RTLD_NOW);
if(!libdvm_dso )
{
printf("error to load libart.so library\n");
return 1;
}
void *libandroid_runtime_dso = dlopen("libandroid_runtime.so", RTLD_NOW);
if(!libandroid_runtime_dso)
{
printf("error to load libandroid_runtime.so library\n");
return 1;
}
JNI_CreateJavaVM_t JNI_CreateJavaVM = NULL;
JNI_CreateJavaVM = (JNI_CreateJavaVM_t) dlsym(libdvm_dso, "JNI_CreateJavaVM");
if(!JNI_CreateJavaVM)
{
printf("error: JNI_CreateJavaVM is not found\n");
return 2;
}
printf("JNI_CreateJavaVM is linked!\n");
// registerNatives_t registerNatives;
// registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "Java_com_android_internal_util_WithFramework_registerNatives");
// if(!registerNatives)
// {
// printf("error: registerNatives is not found\n");
// return 3;
// }
// printf("registerNatives is linked!\n");
int rv = JNI_CreateJavaVM(&javaVM, &jEnv, &args);
if (rv < 0)
{
printf("Unable to Launch JVM %d\n", rv);
return 4;
}
printf("jvm is running!\n");
// if(!registerNatives(*p_env, 0))
// {
// printf("error to register natives\n");
// return 5;
// }
// printf("env is reg!\n");
so, the app is fault when JNI_CreateJavaVM is calling with SIGABRT signal.
I will be grateful for any help!
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAFVaGhvefJ4rdNsm7LtNRS7AJT%3D-s%2B4%3DdfpYB_1MqH7Zw9ER_g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Philippe Simons
2018-07-20 18:00:50 UTC
Permalink
NativeActivty are still running in a JVM (it's a Java class btw)
on Android, every application process is forked from the zygote, which is a
pre warmed-up virtual machine.
You can't escape that.

On Fri, Jul 20, 2018 at 7:49 PM 'Dan Albert' via android-ndk <
Post by 'Dan Albert' via android-ndk
In which case you should be using native_app_glue. The sample is a little
convoluted, but the JavaVM is available as app->activity->vm (where app is
https://github.com/googlesamples/android-ndk/blob/master/native-activity/app/src/main/cpp/main.cpp#L273
Post by Andrew Esh
https://github.com/googlesamples/android-ndk/tree/master/native-activity
https://developer.android.com/reference/android/app/NativeActivity
Post by Philippe Simons
but but...
why would you want to create a JVM, when you application is already
running in a JVM ?
anyway, I'm pretty sure that's not possible
Philippe
Post by Ilya Berezhnoy
Hi everyone,
I try to find out is it possible to create jvm machine to call java
code in native application (c++).
In my project i use gradle and cmake for building.
here is a part of configuration
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mycomp.vpntuner"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
cppFlags "-std=c++14 -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
JavaVM* javaVM = NULL;
JNIEnv* jEnv = NULL;
JavaVMOption opt[1];
opt[0].optionString = "-Djava.class.path=./";
JavaVMInitArgs args;
args.version = JNI_VERSION_1_6;
args.options = opt;
args.nOptions = 1;
args.ignoreUnrecognized = JNI_FALSE;
void *libdvm_dso = dlopen("libart.so", RTLD_NOW);
if(!libdvm_dso )
{
printf("error to load libart.so library\n");
return 1;
}
void *libandroid_runtime_dso = dlopen("libandroid_runtime.so", RTLD_NOW);
if(!libandroid_runtime_dso)
{
printf("error to load libandroid_runtime.so library\n");
return 1;
}
JNI_CreateJavaVM_t JNI_CreateJavaVM = NULL;
JNI_CreateJavaVM = (JNI_CreateJavaVM_t) dlsym(libdvm_dso, "JNI_CreateJavaVM");
if(!JNI_CreateJavaVM)
{
printf("error: JNI_CreateJavaVM is not found\n");
return 2;
}
printf("JNI_CreateJavaVM is linked!\n");
// registerNatives_t registerNatives;
// registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "Java_com_android_internal_util_WithFramework_registerNatives");
// if(!registerNatives)
// {
// printf("error: registerNatives is not found\n");
// return 3;
// }
// printf("registerNatives is linked!\n");
int rv = JNI_CreateJavaVM(&javaVM, &jEnv, &args);
if (rv < 0)
{
printf("Unable to Launch JVM %d\n", rv);
return 4;
}
printf("jvm is running!\n");
// if(!registerNatives(*p_env, 0))
// {
// printf("error to register natives\n");
// return 5;
// }
// printf("env is reg!\n");
so, the app is fault when JNI_CreateJavaVM is calling with SIGABRT signal.
I will be grateful for any help!
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/CAFVaGhvefJ4rdNsm7LtNRS7AJT%3D-s%2B4%3DdfpYB_1MqH7Zw9ER_g%40mail.gmail.com
<https://groups.google.com/d/msgid/android-ndk/CAFVaGhvefJ4rdNsm7LtNRS7AJT%3D-s%2B4%3DdfpYB_1MqH7Zw9ER_g%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CADomA497r7WGSzPk6-zbfm1HRfzAT_wF3BaXW%2BxKcZUzvoD--w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Ilya Berezhnoy
2018-07-21 13:07:52 UTC
Permalink
Hi, Phillipe.

I guess I should say why i try to do it.
So, we have an app written on c++ and successfully build and run on almost
all popular linux distributives (Ubuntu, Fedora, etc). Our current goal is
to port this app to android OS. while making this task i faced a problem
how to build vpn tunnels on adnoid OS (we conider only non-rooted devices)
and i found only one way. This way is to use VpnService class, providing
API for tunnel building. The case i try to realise is to create vm when our
app is started and call VpnService methods when we need to manage vpn
tunnels (create interfaces and so on).
In our project we use openvpn3 client library which requires to redefine
TunBuilderBase class for OS providing special API for tunnel building.
Now my android solution consists of 2 projects. First is UI written on java
and the seccond is our native app beilng built for each platform(arm, eabi,
etc). So, my idea is to run native app as service each time Android OS is
started and UI is run by user when it's necessary to change setings or
state of the service.

пятМОца, 20 Оюля 2018 г., 21:01:12 UTC+3 пПльзПватель Philippe Simons
Post by Philippe Simons
NativeActivty are still running in a JVM (it's a Java class btw)
on Android, every application process is forked from the zygote, which is
a pre warmed-up virtual machine.
You can't escape that.
On Fri, Jul 20, 2018 at 7:49 PM 'Dan Albert' via android-ndk <
Post by 'Dan Albert' via android-ndk
In which case you should be using native_app_glue. The sample is a little
convoluted, but the JavaVM is available as app->activity->vm (where app is
https://github.com/googlesamples/android-ndk/blob/master/native-activity/app/src/main/cpp/main.cpp#L273
Post by Andrew Esh
https://github.com/googlesamples/android-ndk/tree/master/native-activity
https://developer.android.com/reference/android/app/NativeActivity
Post by Philippe Simons
but but...
why would you want to create a JVM, when you application is already
running in a JVM ?
anyway, I'm pretty sure that's not possible
Philippe
Post by Ilya Berezhnoy
Hi everyone,
I try to find out is it possible to create jvm machine to call java
code in native application (c++).
In my project i use gradle and cmake for building.
here is a part of configuration
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mycomp.vpntuner"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
cppFlags "-std=c++14 -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
JavaVM* javaVM = NULL;
JNIEnv* jEnv = NULL;
JavaVMOption opt[1];
opt[0].optionString = "-Djava.class.path=./";
JavaVMInitArgs args;
args.version = JNI_VERSION_1_6;
args.options = opt;
args.nOptions = 1;
args.ignoreUnrecognized = JNI_FALSE;
void *libdvm_dso = dlopen("libart.so", RTLD_NOW);
if(!libdvm_dso )
{
printf("error to load libart.so library\n");
return 1;
}
void *libandroid_runtime_dso = dlopen("libandroid_runtime.so", RTLD_NOW);
if(!libandroid_runtime_dso)
{
printf("error to load libandroid_runtime.so library\n");
return 1;
}
JNI_CreateJavaVM_t JNI_CreateJavaVM = NULL;
JNI_CreateJavaVM = (JNI_CreateJavaVM_t) dlsym(libdvm_dso, "JNI_CreateJavaVM");
if(!JNI_CreateJavaVM)
{
printf("error: JNI_CreateJavaVM is not found\n");
return 2;
}
printf("JNI_CreateJavaVM is linked!\n");
// registerNatives_t registerNatives;
// registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "Java_com_android_internal_util_WithFramework_registerNatives");
// if(!registerNatives)
// {
// printf("error: registerNatives is not found\n");
// return 3;
// }
// printf("registerNatives is linked!\n");
int rv = JNI_CreateJavaVM(&javaVM, &jEnv, &args);
if (rv < 0)
{
printf("Unable to Launch JVM %d\n", rv);
return 4;
}
printf("jvm is running!\n");
// if(!registerNatives(*p_env, 0))
// {
// printf("error to register natives\n");
// return 5;
// }
// printf("env is reg!\n");
so, the app is fault when JNI_CreateJavaVM is calling with SIGABRT signal.
I will be grateful for any help!
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send
<javascript:>.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/CAFVaGhvefJ4rdNsm7LtNRS7AJT%3D-s%2B4%3DdfpYB_1MqH7Zw9ER_g%40mail.gmail.com
<https://groups.google.com/d/msgid/android-ndk/CAFVaGhvefJ4rdNsm7LtNRS7AJT%3D-s%2B4%3DdfpYB_1MqH7Zw9ER_g%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/c6d67e76-7ffb-47f4-b846-a21b80d316c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Dan Albert' via android-ndk
2018-07-21 18:54:18 UTC
Permalink
Yes, every Android app is part of a Java process.
Post by Ilya Berezhnoy
Hi, Phillipe.
I guess I should say why i try to do it.
So, we have an app written on c++ and successfully build and run on almost
all popular linux distributives (Ubuntu, Fedora, etc). Our current goal is
to port this app to android OS. while making this task i faced a problem
how to build vpn tunnels on adnoid OS (we conider only non-rooted devices)
and i found only one way. This way is to use VpnService class, providing
API for tunnel building. The case i try to realise is to create vm when our
app is started and call VpnService methods when we need to manage vpn
tunnels (create interfaces and so on).
In our project we use openvpn3 client library which requires to redefine
TunBuilderBase class for OS providing special API for tunnel building.
Now my android solution consists of 2 projects. First is UI written on
java and the seccond is our native app beilng built for each platform(arm,
eabi, etc). So, my idea is to run native app as service each time Android
OS is started and UI is run by user when it's necessary to change setings
or state of the service.
пятМОца, 20 Оюля 2018 г., 21:01:12 UTC+3 пПльзПватель Philippe Simons
Post by Philippe Simons
NativeActivty are still running in a JVM (it's a Java class btw)
on Android, every application process is forked from the zygote, which is
a pre warmed-up virtual machine.
You can't escape that.
On Fri, Jul 20, 2018 at 7:49 PM 'Dan Albert' via android-ndk <
Post by 'Dan Albert' via android-ndk
In which case you should be using native_app_glue. The sample is a
little convoluted, but the JavaVM is available as app->activity->vm (where
https://github.com/googlesamples/android-ndk/blob/master/native-activity/app/src/main/cpp/main.cpp#L273
Post by Andrew Esh
https://github.com/googlesamples/android-ndk/tree/master/native-activity
https://developer.android.com/reference/android/app/NativeActivity
Post by Philippe Simons
but but...
why would you want to create a JVM, when you application is already
running in a JVM ?
anyway, I'm pretty sure that's not possible
Philippe
Post by Ilya Berezhnoy
Hi everyone,
I try to find out is it possible to create jvm machine to call java
code in native application (c++).
In my project i use gradle and cmake for building.
here is a part of configuration
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mycomp.vpntuner"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
cppFlags "-std=c++14 -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
JavaVM* javaVM = NULL;
JNIEnv* jEnv = NULL;
JavaVMOption opt[1];
opt[0].optionString = "-Djava.class.path=./";
JavaVMInitArgs args;
args.version = JNI_VERSION_1_6;
args.options = opt;
args.nOptions = 1;
args.ignoreUnrecognized = JNI_FALSE;
void *libdvm_dso = dlopen("libart.so", RTLD_NOW);
if(!libdvm_dso )
{
printf("error to load libart.so library\n");
return 1;
}
void *libandroid_runtime_dso = dlopen("libandroid_runtime.so", RTLD_NOW);
if(!libandroid_runtime_dso)
{
printf("error to load libandroid_runtime.so library\n");
return 1;
}
JNI_CreateJavaVM_t JNI_CreateJavaVM = NULL;
JNI_CreateJavaVM = (JNI_CreateJavaVM_t) dlsym(libdvm_dso, "JNI_CreateJavaVM");
if(!JNI_CreateJavaVM)
{
printf("error: JNI_CreateJavaVM is not found\n");
return 2;
}
printf("JNI_CreateJavaVM is linked!\n");
// registerNatives_t registerNatives;
// registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "Java_com_android_internal_util_WithFramework_registerNatives");
// if(!registerNatives)
// {
// printf("error: registerNatives is not found\n");
// return 3;
// }
// printf("registerNatives is linked!\n");
int rv = JNI_CreateJavaVM(&javaVM, &jEnv, &args);
if (rv < 0)
{
printf("Unable to Launch JVM %d\n", rv);
return 4;
}
printf("jvm is running!\n");
// if(!registerNatives(*p_env, 0))
// {
// printf("error to register natives\n");
// return 5;
// }
// printf("env is reg!\n");
so, the app is fault when JNI_CreateJavaVM is calling with SIGABRT signal.
I will be grateful for any help!
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it,
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/CAFVaGhvefJ4rdNsm7LtNRS7AJT%3D-s%2B4%3DdfpYB_1MqH7Zw9ER_g%40mail.gmail.com
<https://groups.google.com/d/msgid/android-ndk/CAFVaGhvefJ4rdNsm7LtNRS7AJT%3D-s%2B4%3DdfpYB_1MqH7Zw9ER_g%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/c6d67e76-7ffb-47f4-b846-a21b80d316c0%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/c6d67e76-7ffb-47f4-b846-a21b80d316c0%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAFVaGhvWzvoWG7WzU%3D6y074NCbvnr8uvff2YZe0wHUc%2B4UqihA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Chris Browet
2018-07-22 10:38:16 UTC
Permalink
VPnService is service. You create your own implementation, which is called
by the system.
Not sure why you think you have to "create a vm".

What you should do is:
- Build the openvpn as a lib with NDK
- Create a native interface lib that will call the openvpn api, and a java
class interfacing with this native lib through jni
- Use the Java interface class from your VpnService implementation, and
possibly from your GUI activity
Post by Ilya Berezhnoy
Hi, Phillipe.
I guess I should say why i try to do it.
So, we have an app written on c++ and successfully build and run on almost
all popular linux distributives (Ubuntu, Fedora, etc). Our current goal is
to port this app to android OS. while making this task i faced a problem
how to build vpn tunnels on adnoid OS (we conider only non-rooted devices)
and i found only one way. This way is to use VpnService class, providing
API for tunnel building. The case i try to realise is to create vm when our
app is started and call VpnService methods when we need to manage vpn
tunnels (create interfaces and so on).
In our project we use openvpn3 client library which requires to redefine
TunBuilderBase class for OS providing special API for tunnel building.
Now my android solution consists of 2 projects. First is UI written on
java and the seccond is our native app beilng built for each platform(arm,
eabi, etc). So, my idea is to run native app as service each time Android
OS is started and UI is run by user when it's necessary to change setings
or state of the service.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/cbef47c5-15eb-4870-8e04-7d58ad83977b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alex Cohn
2018-08-09 17:46:30 UTC
Permalink
See this discussion on
SO: https://stackoverflow.com/questions/51727780/creating-a-native-background-application-using-ndk

BR,
Alex
Post by Ilya Berezhnoy
Hi, Phillipe.
I guess I should say why i try to do it.
So, we have an app written on c++ and successfully build and run on almost
all popular linux distributives (Ubuntu, Fedora, etc). Our current goal is
to port this app to android OS. while making this task i faced a problem
how to build vpn tunnels on adnoid OS (we conider only non-rooted devices)
and i found only one way. This way is to use VpnService class, providing
API for tunnel building. The case i try to realise is to create vm when our
app is started and call VpnService methods when we need to manage vpn
tunnels (create interfaces and so on).
In our project we use openvpn3 client library which requires to redefine
TunBuilderBase class for OS providing special API for tunnel building.
Now my android solution consists of 2 projects. First is UI written on
java and the seccond is our native app beilng built for each platform(arm,
eabi, etc). So, my idea is to run native app as service each time Android
OS is started and UI is run by user when it's necessary to change setings
or state of the service.
пятМОца, 20 Оюля 2018 г., 21:01:12 UTC+3 пПльзПватель Philippe Simons
Post by Philippe Simons
NativeActivty are still running in a JVM (it's a Java class btw)
on Android, every application process is forked from the zygote, which is
a pre warmed-up virtual machine.
You can't escape that.
On Fri, Jul 20, 2018 at 7:49 PM 'Dan Albert' via android-ndk <
Post by 'Dan Albert' via android-ndk
In which case you should be using native_app_glue. The sample is a
little convoluted, but the JavaVM is available as app->activity->vm (where
https://github.com/googlesamples/android-ndk/blob/master/native-activity/app/src/main/cpp/main.cpp#L273
Post by Andrew Esh
https://github.com/googlesamples/android-ndk/tree/master/native-activity
https://developer.android.com/reference/android/app/NativeActivity
Post by Philippe Simons
but but...
why would you want to create a JVM, when you application is already
running in a JVM ?
anyway, I'm pretty sure that's not possible
Philippe
Post by Ilya Berezhnoy
Hi everyone,
I try to find out is it possible to create jvm machine to call java
code in native application (c++).
In my project i use gradle and cmake for building.
here is a part of configuration
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mycomp.vpntuner"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
cppFlags "-std=c++14 -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
JavaVM* javaVM = NULL;
JNIEnv* jEnv = NULL;
JavaVMOption opt[1];
opt[0].optionString = "-Djava.class.path=./";
JavaVMInitArgs args;
args.version = JNI_VERSION_1_6;
args.options = opt;
args.nOptions = 1;
args.ignoreUnrecognized = JNI_FALSE;
void *libdvm_dso = dlopen("libart.so", RTLD_NOW);
if(!libdvm_dso )
{
printf("error to load libart.so library\n");
return 1;
}
void *libandroid_runtime_dso = dlopen("libandroid_runtime.so", RTLD_NOW);
if(!libandroid_runtime_dso)
{
printf("error to load libandroid_runtime.so library\n");
return 1;
}
JNI_CreateJavaVM_t JNI_CreateJavaVM = NULL;
JNI_CreateJavaVM = (JNI_CreateJavaVM_t) dlsym(libdvm_dso, "JNI_CreateJavaVM");
if(!JNI_CreateJavaVM)
{
printf("error: JNI_CreateJavaVM is not found\n");
return 2;
}
printf("JNI_CreateJavaVM is linked!\n");
// registerNatives_t registerNatives;
// registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "Java_com_android_internal_util_WithFramework_registerNatives");
// if(!registerNatives)
// {
// printf("error: registerNatives is not found\n");
// return 3;
// }
// printf("registerNatives is linked!\n");
int rv = JNI_CreateJavaVM(&javaVM, &jEnv, &args);
if (rv < 0)
{
printf("Unable to Launch JVM %d\n", rv);
return 4;
}
printf("jvm is running!\n");
// if(!registerNatives(*p_env, 0))
// {
// printf("error to register natives\n");
// return 5;
// }
// printf("env is reg!\n");
so, the app is fault when JNI_CreateJavaVM is calling with SIGABRT signal.
I will be grateful for any help!
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it,
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/CAFVaGhvefJ4rdNsm7LtNRS7AJT%3D-s%2B4%3DdfpYB_1MqH7Zw9ER_g%40mail.gmail.com
<https://groups.google.com/d/msgid/android-ndk/CAFVaGhvefJ4rdNsm7LtNRS7AJT%3D-s%2B4%3DdfpYB_1MqH7Zw9ER_g%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/c99446b0-c992-42ff-87aa-0c9275b17010%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ilya Berezhnoy
2018-07-21 13:23:28 UTC
Permalink
Do i understand you correctly what any app (even plain native app) is run
inside vm?

пятМОца, 20 Оюля 2018 г., 21:01:12 UTC+3 пПльзПватель Philippe Simons
Post by Philippe Simons
NativeActivty are still running in a JVM (it's a Java class btw)
on Android, every application process is forked from the zygote, which is
a pre warmed-up virtual machine.
You can't escape that.
On Fri, Jul 20, 2018 at 7:49 PM 'Dan Albert' via android-ndk <
Post by 'Dan Albert' via android-ndk
In which case you should be using native_app_glue. The sample is a little
convoluted, but the JavaVM is available as app->activity->vm (where app is
https://github.com/googlesamples/android-ndk/blob/master/native-activity/app/src/main/cpp/main.cpp#L273
Post by Andrew Esh
https://github.com/googlesamples/android-ndk/tree/master/native-activity
https://developer.android.com/reference/android/app/NativeActivity
Post by Philippe Simons
but but...
why would you want to create a JVM, when you application is already
running in a JVM ?
anyway, I'm pretty sure that's not possible
Philippe
Post by Ilya Berezhnoy
Hi everyone,
I try to find out is it possible to create jvm machine to call java
code in native application (c++).
In my project i use gradle and cmake for building.
here is a part of configuration
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.mycomp.vpntuner"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
cppFlags "-std=c++14 -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
JavaVM* javaVM = NULL;
JNIEnv* jEnv = NULL;
JavaVMOption opt[1];
opt[0].optionString = "-Djava.class.path=./";
JavaVMInitArgs args;
args.version = JNI_VERSION_1_6;
args.options = opt;
args.nOptions = 1;
args.ignoreUnrecognized = JNI_FALSE;
void *libdvm_dso = dlopen("libart.so", RTLD_NOW);
if(!libdvm_dso )
{
printf("error to load libart.so library\n");
return 1;
}
void *libandroid_runtime_dso = dlopen("libandroid_runtime.so", RTLD_NOW);
if(!libandroid_runtime_dso)
{
printf("error to load libandroid_runtime.so library\n");
return 1;
}
JNI_CreateJavaVM_t JNI_CreateJavaVM = NULL;
JNI_CreateJavaVM = (JNI_CreateJavaVM_t) dlsym(libdvm_dso, "JNI_CreateJavaVM");
if(!JNI_CreateJavaVM)
{
printf("error: JNI_CreateJavaVM is not found\n");
return 2;
}
printf("JNI_CreateJavaVM is linked!\n");
// registerNatives_t registerNatives;
// registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "Java_com_android_internal_util_WithFramework_registerNatives");
// if(!registerNatives)
// {
// printf("error: registerNatives is not found\n");
// return 3;
// }
// printf("registerNatives is linked!\n");
int rv = JNI_CreateJavaVM(&javaVM, &jEnv, &args);
if (rv < 0)
{
printf("Unable to Launch JVM %d\n", rv);
return 4;
}
printf("jvm is running!\n");
// if(!registerNatives(*p_env, 0))
// {
// printf("error to register natives\n");
// return 5;
// }
// printf("env is reg!\n");
so, the app is fault when JNI_CreateJavaVM is calling with SIGABRT signal.
I will be grateful for any help!
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/8f183b2f-712b-47b3-892b-ed721aa44d54%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send
<javascript:>.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com
<https://groups.google.com/d/msgid/android-ndk/0c65e9c7-067b-407c-9686-bf4e0455590a%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-ndk/CAFVaGhvefJ4rdNsm7LtNRS7AJT%3D-s%2B4%3DdfpYB_1MqH7Zw9ER_g%40mail.gmail.com
<https://groups.google.com/d/msgid/android-ndk/CAFVaGhvefJ4rdNsm7LtNRS7AJT%3D-s%2B4%3DdfpYB_1MqH7Zw9ER_g%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/227ff465-2b42-4469-8961-67b98b553abf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chris Browet
2018-07-21 08:56:28 UTC
Permalink
I bet the OP wants to run some Oracle Java bytecode inside Android.

That won't work. Android is using the java language, but the VM/bytecode is
unrelated to J2SE or J2ME.
If you want to do that, you'd need to bundle your own compatible java vm.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/9aa77a1d-adc6-43df-bc21-7e7bb2fd0394%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...