崩溃Android原生的同时切换到新的活动 [英] Crash in Android Native while changing to new Activity

查看:163
本文介绍了崩溃Android原生的同时切换到新的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序无法打开OpenFeint的仪表盘的方法。原生C ++库的实现使用了cocos2d-x作为一个图形库,但它有一个处理器和一个包装,以允许使用OpenFeint的功能。 OpenFeint的初始化和非活性的方法正常工作。

在UI仪表板的功能,如openLaderBoards或openAchievements要么从JNI调用或在Java的onCreate初始化调用,应用程序崩溃。

编辑:我已经测试和它发生任何活动改变我试试,连我自己新的类

EDIT2:我有一个+100赏金在类似的问题,谁想出了答案得到它

code

活动:

 公共类应用扩展Cocos2dxActivity {
私人Cocos2dxGLSurfaceView mGLView;

OpenFeintX m_kOpenFeintX;

保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);

    //获取的packageName,它被用来设置资源路径
    字符串的packageName = getApplication()getPackageName()。
    super.setPackageName(的packageName);

    InternetConnection.setM_kActivity(本);

    m_kOpenFeintX =新OpenFeintX(本);

    的setContentView(R.layout.applayout);
    mGLView =(Cocos2dxGLSurfaceView)findViewById(R.id.game_gl_surfaceview);
    mGLView.setTextField((的EditText)findViewById(R.id.textField));

// Testspace新的活动,OpenFeint的或自制的
//
//意图myIntent =新的意图(这一点,TestActivity.class);
// startActivityForResult(myIntent,0);
// Dashboard.open();


//在这之后的Cocos2D-X的场景打开

}

 静态{
     的System.loadLibrary(TestProject的);
     加载了cocos2d-X //本地库
 }
 

包装:

 公共类OpenFeintX {

私有静态OpenFeintXHandler ms_kOpenFeintHandler;

公共OpenFeintX(活动kActivity){
    initializeOpenFeint(TestApp,DERP,
            hurr,6546516516541,
            kActivity,ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    ms_kOpenFeintHandler =新OpenFeintXHandler();

}

公共静态无效openLeaderBoards(){
    消息味精=新的Message();
    msg.what = OpenFeintXHandler.SHOW_LEADERBOARDS;
    ms_kOpenFeintHandler.sendMessage(MSG);
}
 

处理器openDashboard功能:

 私人无效openLeaderBoards(){
    的System.out.println(打开仪表盘);
    Dashboard.openLeaderboards();
}
 

清单:

 <应用
    机器人:可调试=真
    机器人:标签=@字符串/ APP_NAME>
    <活动
        机器人:configChanges =方向
        机器人:标签=@字符串/ APP_NAME
        机器人:名称=应用程序
        机器人:screenOrientation =画像
        机器人:主题=@安卓风格/ Theme.NoTitleBar.Fullscreen>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>

            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;

    <活动机器人:名称=com.openfeint.internal.ui.IntroFlow
              机器人:标签=。IntroFlow
              机器人:configChanges =方向| keyboardHidden
              机器人:主题=@风格/ OFNestedWindow/>
    <活动机器人:名称=com.openfeint.api.ui.Dashboard
              机器人:仪表板标签=
              机器人:configChanges =方向| keyboardHidden
              机器人:主题=@风格/ OFNestedWindow/>
    <活动机器人:名称=com.openfeint.internal.ui.Settings
              机器人:设置标签=
              机器人:configChanges =方向| keyboardHidden
              机器人:主题=@风格/ OFNestedWindow/>
    <活动机器人:名称=com.openfeint.internal.ui.NativeBrowser
              机器人:标签=。NativeBrowser
              机器人:configChanges =方向| keyboardHidden
              机器人:主题=@风格/ OFNestedWindow/>
< /用途>
 

堆栈跟踪(不会缩进SO):

http://pastebin.com/jsmSbgw4

解决方案

答案很简单,但复杂。当应用程序更改为一个新的活动,从的cocos2d-X MessageJNI的nativeOnPause方法被调用。这个方法应该叫CCApplication :: sharedApplication(),但我的课的人有previously称为CCApplication析构函数,它清除了共享单为null。

虽然答案很简单修复和具体项目,我打算给什么让我觉得一些建议。请记住,我所有的工具都在Windows和Cygwin的。

首先,Eclipse中做NDK,建立你干净。

单击鼠标右键你的项目 - >属性 - > C / C ++编译。生成器设置选项卡上,命令

  C:\ NVPACK \ cygwin的\斌\ bash.exe -cCD / cygdrive /路径/要/项目和放大器;&安培; ./build_script.sh
 

二,安装调试器。

使用本教程。这可能需要一些时间,试图到那里,但它是值得的。我ADB-服务器​​调用脚本

 出口ANDROID_NDK_ROOT = / cygdrive / C / NVPACK / Android的NDK-R6B /
CD $ ANDROID_NDK_ROOT
./ndk-gdb-eclipse --adb = / cygdrive / C / NVPACK / Android的SDK-窗口/平台工具/ ADB --project = / cygdrive / C /项目/路径--force --verbose
 

三,设置你的logcat中的繁琐。

更新:最后一步,现在可以跳过作为的logcat输出的类别和线整个堆栈跟踪的最新版本

您将获得长期踪迹像在我的问题。若要检查堆栈跟踪误差点按照此的其他教程。我的脚本来访问库

<$p$p><$c$c>C:\NVPACK\android-ndk-r6b\toolchains\x86-4.4.3\$p$pbuilt\windows\bin\i686-android-linux-addr2line.exe -C -f -e C:\路径\为\项目\ libMyLib.so

My application is unable to open OpenFeint dashboard methods. The implementation of the native c++ libraries uses cocos2d-x as a graphic library, but it has a handler and a wrapper to allow the use of OpenFeint functions. OpenFeint initialization and non-activity methods work correctly.

When UI dashboard functions such as openLaderBoards or openAchievements are called either from a Jni call or in the Java onCreate initialization, the application crashes.

EDIT: I have tested and it happens to any Activity change I try, even my own new classes.

EDIT2: I have a +100 bounty in a similar question, anyone who comes up with the answer gets it.

Code

Activity:

public class App extends Cocos2dxActivity{
private Cocos2dxGLSurfaceView mGLView;

OpenFeintX m_kOpenFeintX;

protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    // get the packageName,it's used to set the resource path
    String packageName = getApplication().getPackageName();
    super.setPackageName(packageName);

    InternetConnection.setM_kActivity(this);

    m_kOpenFeintX = new OpenFeintX( this);      

    setContentView(R.layout.applayout);
    mGLView = (Cocos2dxGLSurfaceView) findViewById(R.id.game_gl_surfaceview);
    mGLView.setTextField((EditText)findViewById(R.id.textField));                  

// Testspace for new Activities, OpenFeint or self-made
//
// Intent myIntent = new Intent(this, TestActivity.class);
// startActivityForResult(myIntent, 0);
// Dashboard.open();


// Cocos2d-x scene opens after this

}

 static {
     System.loadLibrary("TestProject");
     // Native library loaded for cocos2d-x
 }

Wrapper:

public class OpenFeintX {

private static OpenFeintXHandler ms_kOpenFeintHandler;

public OpenFeintX(Activity kActivity) {
    initializeOpenFeint("TestApp", "derp",
            "hurr", "6546516516541",
            kActivity, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    ms_kOpenFeintHandler = new OpenFeintXHandler();

}

public static void openLeaderBoards() {     
    Message msg = new Message();
    msg.what = OpenFeintXHandler.SHOW_LEADERBOARDS;
    ms_kOpenFeintHandler.sendMessage(msg);
}

Handler openDashboard function:

private void openLeaderBoards() {
    System.out.println("Opening Dashboard");
    Dashboard.openLeaderboards();
}

Manifest:

<application
    android:debuggable="true"
    android:label="@string/app_name">
    <activity
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:name=".App"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>        

    <activity android:name="com.openfeint.internal.ui.IntroFlow"
              android:label=".IntroFlow"
              android:configChanges="orientation|keyboardHidden"
              android:theme="@style/OFNestedWindow" />
    <activity android:name="com.openfeint.api.ui.Dashboard"
              android:label=".Dashboard"
              android:configChanges="orientation|keyboardHidden"
              android:theme="@style/OFNestedWindow"/>
    <activity android:name="com.openfeint.internal.ui.Settings"
              android:label=".Settings"
              android:configChanges="orientation|keyboardHidden"
              android:theme="@style/OFNestedWindow"/>
    <activity android:name="com.openfeint.internal.ui.NativeBrowser"
              android:label=".NativeBrowser"
              android:configChanges="orientation|keyboardHidden"
              android:theme="@style/OFNestedWindow"/>
</application>

Stacktrace (won't indent in SO):

http://pastebin.com/jsmSbgw4

解决方案

The answer was easy but complex. When the app changes to a new activity, the nativeOnPause method from cocos2d-x MessageJNI is called. This method is supposed to call a CCApplication::sharedApplication(), but one of my classes had previously called the CCApplication destructor, which cleared the shared singleton to null.

Even though the answer is easy to fix and project specific, I am going to give some advice on what made me find it. Keep in mind that all my tools are windows and cygwin.

First, make Eclipse do the ndk-builds for you on clean.

Rightclick your Project-> Properties -> C/C++ Build. Builder Settings tab, Command

  C:\NVPACK\cygwin\bin\bash.exe -c "cd /cygdrive/path/to/project && ./build_script.sh"

Second, setup your debugger.

Using this tutorial. It may take some time and attempts to get there but it is worth it. My adb-server call script is

export ANDROID_NDK_ROOT=/cygdrive/c/NVPACK/android-ndk-r6b/
cd $ANDROID_NDK_ROOT
./ndk-gdb-eclipse --adb=/cygdrive/c/NVPACK/android-sdk-windows/platform-tools/adb     --project=/cygdrive/c/project/path --force --verbose

Third, set your logcat in verbose.

UPDATE: This last step can now be skipped as latest versions of Logcat output the class and line for the whole stacktrace.

You will get long stacktraces like the one in my question. To check where the stacktrace errors point follow this other tutorial. My script to access the library is

C:\NVPACK\android-ndk-r6b\toolchains\x86-4.4.3\prebuilt\windows\bin\i686-android-linux-addr2line.exe -C -f -e c:\path\to\project\libMyLib.so

这篇关于崩溃Android原生的同时切换到新的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆