Problem in running .CPP files & hello-gl2 Sample code on emulator

133 views
Skip to first unread message

Atul Prakash

unread,
Apr 19, 2011, 2:29:16 AM4/19/11
to android-ndk
Hello Friends,

Since, last few days I am working on Android NDK. I had run various
sample codes also like San Angeles, Hello-jni, Bitmap Plasma etc. but
I am unable to run "hello-gl2" sample code on emulator. I am getting
IllegalArgumentException("No configs match configSpec") on emulator
but when I run .apk file of hello-gl2 on Android Device, it run
successfully.

I think OpenGL 2.0 is not supported on Android emulator yet, thats why
hello-gl2 sample is not running on Android emulator.

I also want to run .CPP files using Android NDK, all the samples that
have successfully run on my emulator are running .C files with Android
NDK. But in my project I need to run .CPP files.

So what changes I should do in existing code to run .CPP files with
NDK?

Thanks in advance.

Atul Prakash Singh

mic _

unread,
Apr 19, 2011, 3:39:15 AM4/19/11
to andro...@googlegroups.com
>>I think OpenGL 2.0 is not supported on Android emulator yet, thats why
>>hello-gl2 sample is not running on Android emulator.

Yes, it's not supported. It seems like it's the intention of the Android team to support it eventually, but there's no timeplan for it that I know of.



>>I also want to run .CPP files using Android NDK

There's nothing to it. Just add it to your LOCAL_SRC_FILES in Android.mk. Keep in mind that you'll have to make your JNIEXPORT functions extern "C", or they won't be found when you load the library.

/Michael



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Atul Prakash

unread,
Apr 19, 2011, 4:08:42 AM4/19/11
to android-ndk
Dear Michael,

Thanks for your reply.

Actually in order to run .CPP files using Android NDK, I modified
hello-jni sample code. I have created hello-jni.cpp(just as actual
hello-jni.c) file. I also added .CPP file to LOCAL_SRC_FILES in
Android.mk, but I think there is some problem with my hello-jni.cpp
file.

--------------------------------------
My Android.mk file is as follows:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.cpp

include $(BUILD_SHARED_LIBRARY)
-------------------------------------

My hello-jni.cpp is as follows:

#include <string.h>
#include <jni.h>

extern "C"{
JNIEXPORT jstring JNICALL
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject
thiz );
};
JNIEXPORT jstring JNICALL
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject
thiz )
{
return (env)->NewStringUTF(env, "Hello from JNI !");
}
---------------------------------------

I am trying to make same application as hello-jni sample but instead
of .C file, I am using .CPP file. Please tell me what changes are
needed to run this hello-jni code to run with hello-jni.CPP file.

Regards,

Atul Prakash Singh


On Apr 19, 12:39 pm, mic _ <micol...@gmail.com> wrote:
> >>I think OpenGL 2.0 is not supported on Android emulator yet, thats why
> >>hello-gl2 sample is not running on Android emulator.
>
> Yes, it's not supported. It seems like it's the intention of the Android
> team to support it eventually, but there's no timeplan for it that I know
> of.
>
> >>I also want to run .CPP files using Android NDK
>
> There's nothing to it. Just add it to your LOCAL_SRC_FILES in Android.mk.
> Keep in mind that you'll have to make your JNIEXPORT functions extern "C",
> or they won't be found when you load the library.
>
> /Michael
>

mic _

unread,
Apr 19, 2011, 4:57:42 AM4/19/11
to andro...@googlegroups.com
>>but I think there is some problem with my hello-jni.cpp file.

Do you get an error? If so you should include the error in your post.

/Michael

Atul Prakash

unread,
Apr 19, 2011, 5:20:59 AM4/19/11
to android-ndk
When I run ndk-build command on Cygwin tool, I got error like:

ATUL@ATUL-PC /cygdrive/c/android-ndk-r5b/samples/hello-jni
$ ndk-build
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : hello-jni <= hello-jni.cpp
C:/android-ndk-r5b/samples/hello-jni/jni/hello-jni.cpp: In function
'_jstring* Java_com_example_hell
ojni_HelloJni_stringFromJNI(JNIEnv*, _jobject*)':
C:/android-ndk-r5b/samples/hello-jni/jni/hello-jni.cpp:34: error: no
matching function for call to '
_JNIEnv::NewStringUTF(JNIEnv*&, const char [17])'
C:/android-ndk-r5b/platforms/android-8/arch-arm/usr/include/jni.h:839:
note: candidates are: _jstrin
g* _JNIEnv::NewStringUTF(const char*)
make: *** [/cygdrive/c/android-ndk-r5b/samples/hello-jni/obj/local/
armeabi/objs-debug/hello-jni/hell
o-jni.o] Error 1

On Apr 19, 1:57 pm, mic _ <micol...@gmail.com> wrote:
> >>but I think there is some problem with my hello-jni.cpp file.
>
> Do you get an error? If so you should include the error in your post.
>
> /Michael
>

Atul Prakash

unread,
Apr 19, 2011, 5:39:50 AM4/19/11
to android-ndk
Moreover my Java file i.e. HelloJni.java is like below:

package com.example.hellojni;

import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;


public class HelloJni extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

TextView tv = new TextView(this);
tv.setText( stringFromJNI() );
setContentView(tv);
}

public native String stringFromJNI();

public native String unimplementedStringFromJNI();

static {
System.loadLibrary("hello-jni");

mic _

unread,
Apr 19, 2011, 5:49:31 AM4/19/11
to andro...@googlegroups.com
>>candidates are: _jstring* _JNIEnv::NewStringUTF(const char*)
>>make: *** [/cygdrive/c/android-ndk-r5b/samples/hello-jni/obj/local/armeabi/objs-debug/hello-jni/hell

The solution is to use the candidate suggested. I.e.  env->NewStringUTF("your text here");

/Michael

Atul Prakash

unread,
Apr 19, 2011, 6:17:42 AM4/19/11
to android-ndk
Thanks a lot Michael!!!!!!! It worked....

On Apr 19, 2:49 pm, mic _ <micol...@gmail.com> wrote:
>  >>candidates are: _jstring* _JNIEnv::NewStringUTF(const char*)>>make: ***
>
> [/cygdrive/c/android-ndk-r5b/samples/hello-jni/obj/local/armeabi/objs-debug /hello-jni/hell
>
> The solution is to use the candidate suggested. I.e.
> env->NewStringUTF("your text here");
>
> /Michael
>
Reply all
Reply to author
Forward
0 new messages