【发布时间】:2017-01-27 18:43:19
【问题描述】:
使用 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 安装它不起作用,但如果我通过 Android Studio 的 USB 安装它就可以。
有人有想法吗?
附:已经尝试将 minifyEnabled 设置为 false,没有结果 :( 我听说 Proguard 可以删除构造函数或一段代码,类似的东西。
编辑 崩溃事件的堆栈跟踪:
09-19 20:42:55.127 31614-31614/? E/AndroidRuntime: 致命异常: main 进程:
net.ddns.opencratebox.mycratebox,PID:31614 java.lang.IllegalStateException:找不到方法 android:onClick 的父或祖先上下文中的 registerView(View) 在视图类上定义的属性 id 为 'txvc_register' 的 android.support.v7.widget.AppCompatTextView 在 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) 在 java.lang.reflect.Method.invoke(本机方法) 在 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" />
【问题讨论】:
-
您在上传到 Play 商店之前是否测试了发布 apk?
-
您可以使用 adb install -r myapp.apk 安装发布应用程序并连接调试器并检查 logcat,您将了解其崩溃的原因。
-
我确实测试了 apk,但是在第一个版本之后(不知道我们可以这样做)我会尝试那个 surya 谢谢!
-
在 Android Studio 中,打开 Build Variants 窗口并选择发布版本。现在您可以直接在您的测试设备或模拟器上运行已发布的应用程序。完成此操作后,您可以测试发布版本。您还可以在 Android Studio 中查看 logcat 以确定错误是什么。如果您需要进一步的帮助,请发布您在 logcat 中找到的完整堆栈跟踪。
-
成功了! :) 非常感谢苏里亚!我不确定为什么我不能从我的视图中访问受保护的方法,但它确实有效!你救了妈妈!
标签: java android android-studio android-intent