更改生成类型会导致某些类“无法解析符号”

时间:2019-03-15 13:17:18

标签: android android-studio android-gradle android-proguard android-build-type

当我将构建类型更改为release时,我的某些类在android studio中显示为“找不到符号”。即使显示错误,该应用程序也已成功构建并运行。当我改回调试时,这些文件将被正确识别。

这是我的build.gradle

apply plugin: 'com.android.application'

apply plugin: 'realm-android'

apply plugin: 'io.fabric'

apply plugin: 'com.google.gms.google-services'


android {
    signingConfigs {
        debug {
            keyAlias 'debugkey-name'
            keyPassword 'dpassword'
            storeFile file('debugkey.jks')
            storePassword 'dspassword'
        }
        release {
            keyAlias 'releasekey-name'
            keyPassword 'rpassword'
            storeFile file('releasekey.jks')
            storePassword 'rspassword'
        }
    }

compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
    applicationId "com.app.appname"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    multiDexEnabled true
    versionCode 0
    versionName "0.9.2"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

applicationVariants.all { variant ->

    variant.outputs.all {
        outputFileName = "Appname-${variant.name}-${defaultConfig.versionName}.apk"
    }

}

buildTypes {

    debug {
        minifyEnabled false
        shrinkResources false
        resValue "string", "map_box_key", "mapboxfakeKeyalksdk;lk;laksd;lkas;ldkndasdjasndkaklsjdlaksdjlaksjdkajsdlkj"
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.debug
        debuggable true
        jniDebuggable true
    }

    release {
        minifyEnabled true
        shrinkResources true
        resValue "string", "map_box_key", "mapboxkeyfakekajsdhkajdsklajlskdjlaksjdajlskjdlkjaslkdjlkasjdlkajdlkjaslkd"
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
        debuggable false
        jniDebuggable false
        renderscriptDebuggable false
    }
}

flavorDimensions "Environment"

productFlavors {

    appDemo {
        resValue "string", "app_name", "AppName"
        resValue "string", "url_base_address", "https://baseurl.com"
        dimension "Environment"
    }

    appDev {
        applicationIdSuffix ".dev"
        resValue "string", "app_name", "Dev-AppName"
        resValue "string", "url_base_address", "https://baseurl.com"
        dimension "Environment"
    }

}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
    disable 'LogNotTimber'
}

}

android.sourceSets {

test {
    java.srcDirs = ["src/main/java", "src/mock/java", "src/test/java"]
}

androidTest {
    java.srcDirs = ["src/main/java", "src/mock/java", "src/androidTest/java"]
}

appDemo {
    java.srcDirs = ["src/main/java", "src/real/java"]
}

appDev {
    java.srcDirs = ["src/main/java", "src/real/java"]
}
}

dependencies {
    //so many dependencies
}

repositories {
    mavenCentral()
}

这是我的保护人规则:

-keepclassmembers class 
android.support.design.internal.BottomNavigationMenuView {
    boolean mShiftingMode;
}
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**

-keep class android.support.** { *; }
-keep interface android.support.** { *; }

当我尝试手动导入一些文件时,我看不到某些包和类,但是我可以在android studio中使用搜索选项转到它们(双班) enter image description here

我尝试过的事情:

  1. 清理并重建项目
  2. 使缓存无效并重新启动
  3. 已删除.idea和.gradle文件夹并重建
  4. 同步了项目
  5. 更新构建工具

当我重新调试时,问题就不存在了,所以问题似乎出在我的Gradle配置上。

请帮助我找到问题。

1 个答案:

答案 0 :(得分:-1)

出于测试目的,将您的app build.gradle修改为不针对发布版本优化apk。

release {
        minifyEnabled false
        shrinkResources false

....
..}