Android relase APK无法加载活动

时间:2016-09-20 00:26:55

标签: java android android-studio android-intent

使用Android Studio 2.2时,我的应用程序中的切换活动在使用调试版时非常有效。但是,当我将我的应用程序发布到Google Play时,我可以打开该应用程序,但尝试启动任何其他活动(通过Intent)会使应用程序崩溃。

的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"
    defaultConfig {
        applicationId "net.ddns.opencratebox.mycratebox"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 5
        versionName "0.0.5"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
    compile 'com.google.firebase:firebase-ads:9.4.0'
    compile 'com.google.android.gms:play-services-ads:9.4.0'
    compile 'com.firebase:firebase-client-android:2.3.1'
}



apply plugin: 'com.google.gms.google-services'

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.ddns.opencratebox.mycratebox">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="MyCrateBox"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".source.MVC.View.LaunchActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".source.MVC.View.RegisterActivity" />
        <activity android:name=".source.MVC.View.LoggedActivity" />
    </application>

</manifest>

我要求的唯一许可是INTERNET,我宣布了。无论如何,它与开始活动无关。我不知道发生了什么,因为调试版本的工作原理非常大(通过USB线直接从android studio安装到我的平板电脑上)很多朋友也尝试了它也有同样的结果。

因此,如果我通过Google Play安装它,它就无效,但如果我通过USB从Android Studio安装它,则无效。

有人有想法吗?

P.S。已经尝试将minifyEnabled设置为false,没有结果:(我听说Proguard可以删除构造函数或代码片段,就像那​​样。

修改 崩溃事件的堆栈跟踪:

09-19 20:42:55.127 31614-31614 /? E / AndroidRuntime:致命异常:主要                                                    过程:

  

net.ddns.opencratebox.mycratebox,PID:31614                                                      java.lang.IllegalStateException:找不到方法   用于android:onClick的父或祖先上下文中的registerView(View)   在视图类上定义的属性   android.support.v7.widget.AppCompatTextView,id为'txvc_register'                                                          在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:327)                                                          在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)                                                          在android.view.View.performClick(View.java:5280)                                                          在android.view.View $ PerformClick.run(View.java:21239)                                                          在android.os.Handler.handleCallback(Handler.java:739)                                                          在android.os.Handler.dispatchMessage(Handler.java:95)                                                          在android.os.Looper.loop(Looper.java:234)                                                          在android.app.ActivityThread.main(ActivityThread.java:5526)                                                          at java.lang.reflect.Method.invoke(Native Method)                                                          在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

应该启动其他活动的代码:

protected void registerView(View view) {
        Intent intent = new Intent(this, RegisterActivity.class);
        startActivity(intent);
    }

代表点击按钮的XML:

<TextView
        android:id="@+id/txvc_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btn_register"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="42dp"
        android:clickable="true"
        android:linksClickable="false"
        android:onClick="registerView"
        android:text="@string/or_register"
        android:textColor="@color/abc_btn_colored_borderless_text_material" />

1 个答案:

答案 0 :(得分:3)

通过简单地将onClick调用的方法的可见性从protected更改为public来解决。

public void registerView(View view) {
        Intent intent = new Intent(this, RegisterActivity.class);
        startActivity(intent);
    }