# Run Java code from C++ using JNI (Android)

**URL:** <https://forums.unrealengine.com/t/run-java-code-from-c-using-jni-android/340143>\
**Category:** Mobile\
**Tags:** error, unreal-engine, Android, java, CPP, question\
**Created:** [November 30, 2015, 6:14pm UTC](https://forums.unrealengine.com/t/run-java-code-from-c-using-jni-android/340143 "2015-11-30T18:14:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_a2765d2b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a2765d2b](https://forums.unrealengine.com/u/anonymous_user_a2765d2b)\
**Post date:** [November 30, 2015, 6:14pm UTC](https://forums.unrealengine.com/t/run-java-code-from-c-using-jni-android/340143/1 "2015-11-30T18:14:49Z")

</div>

Hello,  
I want to run some java code from C++ but every time I search for a java class using `env->FindClass` the application crashes telling me that the class do not exist. The class exist but somehow the `JNIEnv` that I get do not have access to the new java classes. How can I fix that?

To get the JNIENv I do the following:

```
JNIEnv* env = FAndroidApplication::GetJavaEnv();

```

I’ve also tried the following, but I go the same result:

```
JNIEnv* Env = NULL;
GJavaVM->GetEnv((void **)&Env, JNI_VERSION_1_6);
jint AttachThreadResult = GJavaVM->AttachCurrentThread(&Env, NULL);

```

Thanks for the help

---

<div class="post-metadata">

**Author:** ![Gandore](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gandore](https://forums.unrealengine.com/u/Gandore)\
**Post date:** [December 1, 2015, 3:35am UTC](https://forums.unrealengine.com/t/run-java-code-from-c-using-jni-android/340143/2 "2015-12-01T03:35:51Z")

</div>

Same issue here, I’m using this code but it doesn compile  
[http://www.codeproject.com/Articles/993067/Calling-Java-from-Cplusplus-with-JNI](http://www.codeproject.com/Articles/993067/Calling-Java-from-Cplusplus-with-JNI)

It gets stuck in : jint rc = JNI\_CreateJavaVM(&jvm, (void\*\*)&env, &vm\_args);

if you find a solution please post, I am trying to implement GCM on my game but I can´t get the InstanceID of the app without java

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a2765d2b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a2765d2b](https://forums.unrealengine.com/u/anonymous_user_a2765d2b)\
**Post date:** [December 1, 2015, 8:12am UTC](https://forums.unrealengine.com/t/run-java-code-from-c-using-jni-android/340143/3 "2015-12-01T08:12:42Z")

</div>

My code compiles, it crashes during runtime, probably you have an other issue

---

<div class="post-metadata">

**Author:** ![Solvay](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Solvay](https://forums.unrealengine.com/u/Solvay)\
**Post date:** [March 15, 2016, 10:40am UTC](https://forums.unrealengine.com/t/run-java-code-from-c-using-jni-android/340143/4 "2016-03-15T10:40:12Z")

</div>

I have the same issue. Don’t you solve this problem yet?

---

<div class="post-metadata">

**Author:** ![Solvay](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Solvay](https://forums.unrealengine.com/u/Solvay)\
**Post date:** [March 25, 2016, 8:15am UTC](https://forums.unrealengine.com/t/run-java-code-from-c-using-jni-android/340143/5 "2016-03-25T08:15:33Z")

</div>

In my case, the problem was ProGuard tool. ProGuard encrypts names of Java classes to fight against decompilation and hacking. It also affects my normal codes trying to access Java classes. After I disabled ProGuard, the problem was solved.

You can configure ProGuard by editing a text file located in the path below.

Engine/Build/Android/Java/proguard-project.txt

For your information, [앱 축소, 난독화 및 최적화 &nbsp;|&nbsp; Android 개발자 &nbsp;|&nbsp; Android Developers](http://developer.android.com/intl/ko/tools/help/proguard.html#configuring)
