APK error: Android app runs perfectly fine on emulator/device but when I download from the PlayStore the app always crashes on startup

APK error: Android app runs perfectly fine on emulator/device but when I download from the PlayStore the app always crashes on startup

我的应用程序在我的模拟器上工作得很好,当我 运行 它通过我 phone 上的 USB 运行时。但是,当我从 PlayStore 下载它时,它会在启动时崩溃 这是日志:

java.lang.AbstractMethodError: abstract method "void android.app.Application$ActivityLifecycleCallbacks.onActivityCreated(android.app.Activity, android.os.Bundle)"
at android.app.Application.dispatchActivityCreated(Application.java:190)
at android.app.Activity.onCreate(Activity.java:954)
at com.stackkedteam.feedshare.DispatchActivity.onCreate(Unknown Source)  //<--- this line is bolded in the log
at android.app.Activity.performCreate(Activity.java:6097)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2440)
at android.app.ActivityThread.access0(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5430)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:913)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)

这是 DispatchActivity:

package com.stackkedteam.feedshare;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.parse.ParseUser;

 /* Activity which starts an intent for either the logged in (MainActivity) or logged out
 * (SignUpOrLoginActivity) activity.
 */
public class DispatchActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        // Check if there is current user info
        if (ParseUser.getCurrentUser() != null) {
            // Start an intent for the logged in activity
            startActivity(new Intent(this, MealListActivity.class));
            finish();
        } else {
            // Start and intent for the logged out activity
            startActivity(new Intent(this, SignUpOrLoginActivity.class));
            finish();
        }
    }
}

我将包名从 com.example.xxxxxx 更改为 com.stackkedteam.feedshare。是因为这个原因,apk 不工作吗?

这是我的混淆器-rules.pro:

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-keepattributes SourceFile,LineNumberTable
-keep class com.parse.*{ *; }
-dontwarn com.parse.**
-dontwarn io.fabric.**
-dontwarn bolts.**
-dontwarn com.squareup.picasso.**
-keep class com.stackkedteam.feedshare.DispatchActivity {*;}
-keepclasseswithmembernames class * {
    native <methods>;
}

这是我在生成 APK 时忽略的 gradle 消息警告:

这里是 gradle 文件:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 11
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.stackkedteam.feedshare"
        minSdkVersion 11
        targetSdkVersion 23
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    //compile 'com.android.support:support-v4:18.0.0'
    compile 'com.android.support:support-v4:23.0.+'
    compile files('libs/Parse-1.4.3.jar')
    compile 'com.parse.bolts:bolts-android:1.+'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.3@aar') {
        transitive = true;
    }
}

很明显,根据堆栈跟踪,您的 proguard 文件需要修改。

-保持class com.parse.{ *; } -保持 class io.fabric.{ *; }

所以首先测试更改并查看当 progurd 运行时堆栈跟踪中留下的内容

好吧,原来我的前面少了一个星号

-keep class com.parse.**{ *;}

这就是解决方法。花了很长时间才弄明白。

这是混淆文件:

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/Ben/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-keepattributes SourceFile,LineNumberTable
-keep class com.parse.**{ *; }
-dontwarn com.parse.**
-dontwarn io.fabric.**
-dontwarn bolts.**
-dontwarn com.squareup.picasso.**
-keep class com.stackkedteam.feedshare.DispatchActivity {*;}
-keepclasseswithmembernames class * {
    native <methods>;
}