【问题标题】:APK error: Android app runs perfectly fine on emulator/device but when I download from the PlayStore the app always crashes on startupAPK 错误:Android 应用程序在模拟器/设备上运行得非常好,但是当我从 PlayStore 下载时,应用程序总是在启动时崩溃
【发布时间】:2015-11-30 17:04:32
【问题描述】:

我的应用程序在我的模拟器上运行良好,当我通过手机上的 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.access$800(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不起作用?

这是我的 proguard-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;
    }
}

【问题讨论】:

    标签: android parse-platform apk proguard


    【解决方案1】:

    很明显,通过堆栈跟踪,您的 proguard 文件需要一些修改。

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

    所以先测试更改,然后查看 progurd 运行时堆栈跟踪中剩下的内容

    【讨论】:

    • 快速问题,你如何从堆栈跟踪中得知它需要修改的 proguard 以及在 proguard 中要修改什么?我是这方面的绝对新手,文档令人困惑。
    • 我测试了它,这是应用程序崩溃时的错误日志:java.lang.AbstractMethodError: abstract method not implemented at a.a.a.a.c.onActivityCreated(ActivityLifecycleManager.java) at android.app.Application.dispatchActivityCreated(Application.java:209) at android.app.Activity.onCreate(Activity.java:956) at com.stackkedteam.feedshare.DispatchActivity.onCreate(DispatchActivity.java:18) )
    【解决方案2】:

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

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

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

    这里是proguard文件:

    # 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>;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-19
      • 1970-01-01
      • 2022-11-13
      • 1970-01-01
      • 1970-01-01
      • 2011-09-24
      • 1970-01-01
      相关资源
      最近更新 更多