问题
I have been modifying and playing around with this project:
source code : https://bitbucket.org/viet0904163136/gba-android/src
It's a gameboy advance emulator licensed under GPLv2. Every thing works ok until i change the packagename in the android manifest file.
Without the package name changed the app works without a problem. But when the package name is changed the SDLactivity quits with this message: (i renamed it to com.gba.emu)
09-01 12:23:16.409: I/SDL(884): SDL_Android_Init()
09-01 12:23:16.409: W/dalvikvm(884): JNI WARNING: received null jclass
09-01 12:23:16.419: W/dalvikvm(884):in Lorg/libsdl/app/SDLActivity;.nativeInit:()V (GetStaticMethodID)
09-01 12:23:16.419: I/dalvikvm(884): "SDLThread" prio=5 tid=17 NATIVE
09-01 12:23:16.419: I/dalvikvm(884): | group="main" sCount=0 dsCount=0 obj=0x4183fc00 self=0x2a2b6f88
09-01 12:23:16.419: I/dalvikvm(884): | sysTid=1148 nice=0 sched=0/0 cgrp=apps handle=707490776
09-01 12:23:16.479: I/dalvikvm(884): | state=R schedstat=( 4273431 73605592 10 ) utm=0 stm=0 core=0
09-01 12:23:16.589: I/dalvikvm(884): #00 pc 000012fe /system/lib/libcorkscrew.so (unwind_backtrace_thread+29)
09-01 12:23:16.700: I/dalvikvm(884): #01 pc 0005fd92 /system/lib/libdvm.so (dvmDumpNativeStack(DebugOutputTarget const*, int)+33)
09-01 12:23:16.700: I/dalvikvm(884): #02 pc 00053e28 /system/lib/libdvm.so (dvmDumpThreadEx(DebugOutputTarget const*, Thread*, bool)+395)
09-01 12:23:16.700: I/dalvikvm(884): #03 pc 00053e96 /system/lib/libdvm.so (dvmDumpThread(Thread*, bool)+25)
09-01 12:23:16.700: I/dalvikvm(884): #04 pc 000385c0 /system/lib/libdvm.so
09-01 12:23:16.700: I/dalvikvm(884): #05 pc 00038896 /system/lib/libdvm.so
09-01 12:23:16.709: I/dalvikvm(884): #06 pc 0003985c /system/lib/libdvm.so
09-01 12:23:16.709: I/dalvikvm(884): #07 pc 0003dbe2 /system/lib/libdvm.so
09-01 12:23:16.709: I/dalvikvm(884): #08 pc 000f3bfa /data/app-lib/com.gba.emu- 1/libmain.so (SDL_Android_Init+549)
09-01 12:23:16.709: I/dalvikvm(884): #09 pc 000a7770 /data/app-lib/com.gba.emu-1/libmain.so (Java_org_libsdl_app_SDLActivity_nativeInit+3)
09-01 12:23:16.709: I/dalvikvm(884): #10 pc 0001dc4c /system/lib/libdvm.so (dvmPlatformInvoke+112)
09-01 12:23:16.739: I/dalvikvm(884): #11 pc 0004dcaa /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+393)
09-01 12:23:16.739: I/dalvikvm(884): #12 pc 000385e0 /system/lib/libdvm.so (dvmCheckCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+7)
09-01 12:23:16.739: I/dalvikvm(884): #13 pc 0004f696 /system/lib/libdvm.so (dvmResolveNativeMethod(unsigned int const*, JValue*, Method const*, Thread*)+181)
09-01 12:23:16.739: I/dalvikvm(884): #14 pc 00027060 /system/lib/libdvm.so
09-01 12:23:16.739: I/dalvikvm(884): #15 pc 0002b580 /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184)
09-01 12:23:16.739: I/dalvikvm(884): #16 pc 0005fcbc /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+291)
09-01 12:23:16.749: I/dalvikvm(884): #17 pc 0005fce6 /system/lib/libdvm.so (dvmCallMethod(Thread*, Method const*, Object*, JValue*, ...)+19)
09-01 12:23:16.749: I/dalvikvm(884): #18 pc 00054a6e /system/lib/libdvm.so
09-01 12:23:16.749: I/dalvikvm(884): #19 pc 0000ca58 /system/lib/libc.so (__thread_entry+72)
09-01 12:23:16.749: I/dalvikvm(884): #20 pc 0000cbd4 /system/lib/libc.so (pthread_create+208)
09-01 12:23:16.749: I/dalvikvm(884): at org.libsdl.app.SDLActivity.nativeInit(Native Method)
09-01 12:23:16.749: I/dalvikvm(884): at org.libsdl.app.SDLMain.run(SDLActivity.java:704)
09-01 12:23:16.759: I/dalvikvm(884): at java.lang.Thread.run(Thread.java:841)
09-01 12:23:16.759: E/dalvikvm(884): VM aborting
There are 2 packages in the src folder ("com.van.gba" and "org.libsdl.app"). Everything in the jni is pointed to org.libsdl.app. The manifest package name is com.van.gba
when i change com.van.gba it breaks.
So i am wondering, what is causing this problem? I can't find a single refrence to the original package name (com.van.gba) in the jni files.
This error can be simulated by changing the package hierarchy and android manifest package name. (both called com.van.gba) It will occur when loading a gba rom.
(note: before compiling the jni add SDL2_image to LOCAL_STATIC_LIBRARIES += zlib png ( like this LOCAL_STATIC_LIBRARIES += zlib png SDL2_image
) in the android.mk file under the folder "src")
回答1:
If you look at SDL_android_main.c, you will find, e.g.
void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject obj)
{
...
}
Which defines a native method of class SDLActivity
in package org.libsdl.app
. You must rename all such functions in your .c files if the package of the SDLActivity
is renamed.
On the other hand, there is no need to rename the package of the Java class when you rename the APK package. It is also often convenient to create a small "native wrapper" Java class, and move all native methods to this class; then call them from this class. This is especially relevant for static native methods.
==== Update ====
Here is another place where the package name is hardwired:
See class com.van.gba.SelectGameActivity
String strTempPath = Environment.getExternalStorageDirectory().getAbsolutePath();
strTempPath += "/Android/data/";
strTempPath += SelectGameActivity.this.getPackageName();
File dir = new File(strTempPath);
It is looking for some files based on its package name; it assumes that its package name is equal to the APK package name. There are probably more places like this in your code. When you have them fixed, you will be able to rename the APK package.
来源:https://stackoverflow.com/questions/25595634/changing-package-name-android-manifest-causes-problems-jni