【问题标题】:Cannot find symbol on clean generate release在干净的生成版本上找不到符号
【发布时间】:2017-08-14 00:53:35
【问题描述】:

我正在创建一个外部模块,或者我应该为现有的移动项目应用程序创建一个库,因为我无法调整其内部结构(代码、配置等),

这个库的唯一目的是执行 API 调用(即在服务器和客户端项目(app)之间接受和返回数据),它在开发中工作得非常好,但是当我尝试构建库时方式

gradlew clean build generateRelease --stacktrace

我在堆栈跟踪中遇到这些类型的错误

 error: cannot find symbol
 @SerializedName("FirstName")
 ^

我发现改造确实有

  minifyEnabled true

然后我学到了有关 proguard 规则的东西 ,使用来自不同来源和不同测试的这些行,

 -keep class com.google.code.gson.** { *; }
 -keep class com.google.code.gson.annotations** { *; }
 -keep class retrofit2.** { *; }

 -keepclassmembernames interface * {
     @retrofit.http.* <methods>;
 }

 -keep class retrofit2.** { *; }
 -keepclassmembernames interface * {
     @retrofit2.http.* <methods>;
 }

 -keep class sun.misc.Unsafe { *; }
 -keep class com.google.code.gson.stream.** { *; }

 -keepattributes Signature
 -keepattributes *Annotation*

这些规则的不同组合,但我在构建时仍然遇到问题,这些是在 Library/Module 的 proguard-rules.pro

上编码的

我不知道问题是否来自 proguard 规则,因为我已经测试了很多 -keep 属性。任何帮助将不胜感激。

这是库的 build.gradle

 apply plugin: 'com.android.library'



android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

         testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:25.3.0'

    compile 'com.squareup.retrofit2:retrofit:2.2.0'
    compile 'com.squareup.retrofit2:converter-gson:2.2.0'
    compile 'com.google.code.gson:gson:2.8.0'
}

apply from: 'https://raw.githubusercontent.com/blundell/release-android-
library/master/android-release-aar.gradle'

【问题讨论】:

    标签: gradle gson proguard retrofit2 android-proguard


    【解决方案1】:

    对我来说,在将以下内容添加到您的 proguard 文件后,您的项目已成功构建并启用了缩小:

    -dontwarn okio.**
    -dontwarn retrofit2.Platform$Java8
    

    【讨论】:

    • 是的,我尝试将其上传为二进制文件并将其用作二进制文件,它运行良好,感谢您的回答和我需要的 proguard 代码,它确实消除了我的疑虑。
    猜你喜欢
    • 2011-02-16
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    • 2022-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多