首页   注册   登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
拉勾
V2EX  ›  问与答

关于安卓 release 版本闪退的问题

  •  
  •   feilong · 363 天前 · 3004 次点击
    这是一个创建于 363 天前的主题,其中的信息可能已经有所发展或是发生改变。

    之前一直编译成为 debug 版本没有问题,但是切换到 release 版本时候,安卓 4.4 闪退了安卓 8.1 正常运行,求助大佬们

    apk 是这个 https://github.com/feilongfl/Cimoc/releases/download/sign10/Cimoc.apk

    代码 https://github.com/feilongfl/Cimoc/tree/test-sign

    build.gradle

    apply plugin: 'com.android.application'
    apply plugin: 'org.greenrobot.greendao'
    
    android {
        compileSdkVersion 27
        buildToolsVersion "27.0.3"
    
        defaultConfig {
            applicationId "com.hiroshi.cimoc"
            minSdkVersion 15
            targetSdkVersion 27
            versionCode 1
            versionName "1.4.8.8013"
            resConfigs "en", "zh"
        }
        signingConfigs {
            release {
                storeFile file(".key.jks")
                storePassword System.getenv("KEYSTORE_PASS")
                keyAlias System.getenv("ALIAS_NAME")
                keyPassword System.getenv("ALIAS_PASS")
            }
        }
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
                shrinkResources true
                zipAlignEnabled true
                signingConfig signingConfigs.release
            }
            android.applicationVariants.all { variant ->
                variant.outputs.all {
                    outputFileName = "Cimoc.apk"
                }
            }
        }
    }
    
    greendao {
        schemaVersion 10
    }
    
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:support-v13:27.0.2'
        compile 'com.android.support:appcompat-v7:27.0.2'
        compile 'com.android.support:recyclerview-v7:27.0.2'
        compile 'com.android.support:design:27.0.2'
        compile 'com.jakewharton:butterknife:8.8.1'
        annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
        compile 'org.greenrobot:greendao:3.2.2'
        compile 'com.squareup.okhttp3:okhttp:3.9.1'
        compile 'com.facebook.fresco:fresco:1.8.0'
        compile 'org.jsoup:jsoup:1.11.2'
        compile 'org.adw.library:discrete-seekbar:1.0.1'
        compile 'io.reactivex:rxjava:1.2.4'
        compile 'io.reactivex:rxandroid:1.2.1'
    }
    

    .travis.yml

    language: android
    android:
      components:
      - tools
      - platform-tools
      - build-tools-27.0.3
      - android-27
      - add-on
      - extra
    licenses:
    - android-sdk-license-.+
    before_install:
    - yes | sdkmanager "platforms;android-27"
    jdk:
    - oraclejdk8
    before_script:
    - chmod +x gradlew
    script:
    - "./gradlew assembleRelease"
    before_cache:
    - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
    cache:
      directories:
      - "$HOME/.m2"
      - "$HOME/.gradle/caches/"
      - "$HOME/.gradle/wrapper/"
    deploy:
      provider: releases
      api_key:
        secure: [key]
    #  file: "app/build/outputs/apk/debug/Cimoc.apk"
      file: "app/build/outputs/apk/release/Cimoc.apk"
      skip_cleanup: true
      on:
        repo: feilongfl/Cimoc
        branch:
          - release-tci
          - test-sign
        tags: true
    
    9 回复  |  直到 2018-03-23 07:37:50 +08:00
        1
    XinLake   363 天前 via Android
    release 做了混淆? 目测混淆配置方面问题。
    闪退可以看 logcat,那些详细信息基本可以定位到问题。
        2
    feilong   363 天前
    上网查了一推,看了 android monitor 的记录

    错误是这么说的
    > 03-22 19:02:03.516: W/System.err(4259): at com.hiroshi.cimoc.App.onCreate(App.java:59)

    app.java:59 是
    > Fresco.initialize(this);


    log

    ```
    03-22 19:02:03.374: I/ActivityManager(835): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.hiroshi.cimoc/.ui.activity.MainActivity bnds=[8,474][184,678]} from pid 1118
    03-22 19:02:03.397: I/BufferQueue(181): [Starting com.hiroshi.cimoc](this:0xb7faf008,id:1757,api:0,p:-1,c:181) setConsumerName: Starting com.hiroshi.cimoc
    03-22 19:02:03.397: I/BufferQueue(181): [Starting com.hiroshi.cimoc](this:0xb7faf008,id:1757,api:0,p:-1,c:181) setDefaultBufferSize: w=1, h=1
    03-22 19:02:03.402: I/ActivityManager(835): Start proc com.hiroshi.cimoc for activity com.hiroshi.cimoc/.ui.activity.MainActivity: pid=4259 uid=10142 gids={50142, 3003, 1028, 1015}
    03-22 19:02:03.409: I/BufferQueue(181): [Starting com.hiroshi.cimoc](this:0xb7faf008,id:1757,api:0,p:-1,c:181) setDefaultBufferSize: w=720, h=1280
    03-22 19:02:03.427: I/BufferQueue(181): [Starting com.hiroshi.cimoc](this:0xb7faf008,id:1757,api:0,p:835,c:181) connect: api=2 producer=(835:system_server) producerControlledByApp=false
    03-22 19:02:03.428: I/BufferQueue(181): [Starting com.hiroshi.cimoc](this:0xb7faf008,id:1757,api:2,p:835,c:181) new GraphicBuffer needed
    03-22 19:02:03.442: I/GLConsumer(181): [Starting com.hiroshi.cimoc](this:0xb7f897b8,api:2) [void* android::GLConsumer::createImage(EGLDisplay, const android::sp<android::GraphicBuffer>&, const android::Rect&)]
    03-22 19:02:03.472: D/dalvikvm(4259): open_cached_dex_file : /data/app/com.hiroshi.cimoc-1.apk /data/dalvik-cache/data@app@com.hiroshi.cimoc-1.apk@classes.dex
    03-22 19:02:03.516: W/System.err(4259): at com.hiroshi.cimoc.App.onCreate(App.java:59)
    03-22 19:02:03.519: I/dalvikvm(4259): Could not find method android.provider.DocumentsContract.getTreeDocumentId, referenced from method com.hiroshi.cimoc.k.a.a
    03-22 19:02:03.555: I/ActivityManager(835): Process com.hiroshi.cimoc (pid 4259) has died.
    03-22 19:02:03.578: I/ActivityManager(835): Start proc com.hiroshi.cimoc for activity com.hiroshi.cimoc/.ui.activity.MainActivity: pid=4274 uid=10142 gids={50142, 3003, 1028, 1015}
    03-22 19:02:03.659: D/dalvikvm(4274): open_cached_dex_file : /data/app/com.hiroshi.cimoc-1.apk /data/dalvik-cache/data@app@com.hiroshi.cimoc-1.apk@classes.dex
    03-22 19:02:03.681: W/System.err(4274): at com.hiroshi.cimoc.App.onCreate(App.java:59)
    03-22 19:02:03.683: I/dalvikvm(4274): Could not find method android.provider.DocumentsContract.getTreeDocumentId, referenced from method com.hiroshi.cimoc.k.a.a
    03-22 19:02:03.703: I/ActivityManager(835): Process com.hiroshi.cimoc (pid 4274) has died.
    03-22 19:02:03.715: I/ActivityManager(835): Start proc com.hiroshi.cimoc for activity com.hiroshi.cimoc/.ui.activity.MainActivity: pid=4292 uid=10142 gids={50142, 3003, 1028, 1015}
    03-22 19:02:03.766: D/dalvikvm(4292): open_cached_dex_file : /data/app/com.hiroshi.cimoc-1.apk /data/dalvik-cache/data@app@com.hiroshi.cimoc-1.apk@classes.dex
    03-22 19:02:03.791: W/System.err(4292): at com.hiroshi.cimoc.App.onCreate(App.java:59)
    03-22 19:02:03.793: I/dalvikvm(4292): Could not find method android.provider.DocumentsContract.getTreeDocumentId, referenced from method com.hiroshi.cimoc.k.a.a
    03-22 19:02:03.813: I/ActivityManager(835): Process com.hiroshi.cimoc (pid 4292) has died.
    03-22 19:02:03.813: W/ActivityManager(835): Force removing ActivityRecord{42d5b380 u0 com.hiroshi.cimoc/.ui.activity.MainActivity t238}: app died, no saved state
    03-22 19:02:03.816: I/BufferQueue(181): [Starting com.hiroshi.cimoc](this:0xb7faf008,id:1757,api:2,p:-1,c:181) disconnect: api=2
    03-22 19:02:03.816: I/BufferQueue(181): [Starting com.hiroshi.cimoc](this:0xb7faf008,id:1757,api:0,p:-1,c:181) getReleasedBuffers: returning mask 0xffffffff
    03-22 19:02:03.816: I/GLConsumer(181): [Starting com.hiroshi.cimoc](this:0xb7f897b8,api:0) destroying EGLImage dpy=0x1 img=0x10000013
    03-22 19:02:03.824: I/BufferQueue(181): [Starting com.hiroshi.cimoc](this:0xb7faf008,id:1757,api:0,p:-1,c:-1) consumerDisconnect
    03-22 19:02:03.825: I/BufferQueue(181): [Starting com.hiroshi.cimoc](this:0xb7faf008,id:1757,api:0,p:-1,c:-1) ~BufferQueue
    03-22 19:02:03.825: D/ConsumerBase(181): [Starting com.hiroshi.cimoc] onLastStrongRef

    ```
        3
    feilong   363 天前
    @XinLake
    按照你的说法,去掉了下面这四行

    ```
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    shrinkResources true
    zipAlignEnabled true
    ```

    然后竟然真的没问题了,但是问题的根本应该不是这里吧
        4
    zjp   363 天前 via Android
    大概率是混淆的问题 检查 proguard 文件
        5
    feilong   363 天前
    @zjp 感谢大佬们分析
    fork 别人的项目,这是我头一次看到混淆😭,看到这个文件一脸懵逼,慢慢百度中😭

    proguard-rules.pro

    ```
    # Add project specific ProGuard rules here.
    # By default, the flags in this file are appended to flags specified
    # in D:\Developer\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 *;
    #}

    -optimizationpasses 3

    -keepattributes SourceFile, LineNumberTable

    # fresco
    -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
    -keep @com.facebook.common.internal.DoNotStrip class *
    -keepclassmembers class * {
    @com.facebook.common.internal.DoNotStrip *;
    }
    -dontwarn okio.**
    -dontwarn javax.annotation.**
    -dontwarn com.facebook.infer.**

    # greenDAO
    -keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
    public static java.lang.String TABLENAME;
    }
    -keep class **$Properties
    -dontwarn org.greenrobot.greendao.database.**
    -dontwarn org.greenrobot.greendao.rx.**

    # ButterKnife
    -keep public class * implements butterknife.internal.ViewBinder { public <init>(); }
    -keep class butterknife.*
    -keepclasseswithmembernames class * { @butterknife.* <methods>; }
    -keepclasseswithmembernames class * { @butterknife.* <fields>; }

    # OkHttp3
    -keep class okhttp3.** { *; }
    -keep interface okhttp3.** { *; }
    -dontwarn okhttp3.**

    # rhino
    -dontwarn org.mozilla.javascript.**
    -dontwarn org.mozilla.classfile.**
    -keep class org.mozilla.javascript.** { *; }

    # jsoup
    -keeppackagenames org.jsoup.nodes

    # andrroid v4 v7
    -dontwarn android.support.v4.**
    -dontwarn android.support.v7.**

    # rx
    -dontwarn sun.misc.**
    -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
    long producerIndex;
    long consumerIndex;
    }
    -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode producerNode;
    }
    -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode consumerNode;
    }
    ```
        6
    feilong   363 天前
    我跑到 fresco 官网上,参考(抄上)这个( https://www.fresco-cn.org/docs/proguard.html)[https://www.fresco-cn.org/docs/proguard.html],然后编译可以运行了(ಥ _ ಥ)

    @XinLake @zjp
    感谢两位大佬指出问题
        7
    zjp   363 天前 via Android
    @feilong 我遇到的所有在 debug 包正常但 release 有问题的情况都是因为混淆规则没写好😂
        8
    Jimjay   363 天前 via Android
    logcat 有日志吗
        9
    feilong   362 天前
    @Jimjay
    2 楼有 android monitor 的日志,和 logcat 一不一样我就不知道了
    关于   ·   FAQ   ·   API   ·   我们的愿景   ·   广告投放   ·   感谢   ·   实用小工具   ·   1154 人在线   最高记录 4385   ·  
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.3 · 16ms · UTC 23:10 · PVG 07:10 · LAX 16:10 · JFK 19:10
    ♥ Do have faith in what you're doing.
    沪ICP备16043287号-1