竹山一叶

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

Android Studio运行时候报packageOfficialDebug错误

报错信息为

Error:A problem was found with the configuration of task':watch:packageOfficialDebug'.
File '...\build\intermediates\res\resources-official-debug-stripped.ap_' specified for property 'resourceFile' does not exist.

解决方法一:

这个大多数原因是开启了混淆造成的,关闭Debug模式下的混淆开关后重新编译即可,代码如下:

buildTypes {
        release {
            buildConfigField("boolean", "LOG_DEBUG", "false")
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            shrinkResources false
            buildConfigField("boolean", "LOG_DEBUG", "true")
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

minifyEnabled即以前的runProguard,用来控制是否混淆。

shrinkResources为true时自动去掉多余资源。

注:Gradle2.0以上的版本minifyEnabled字段为true时已经包含了shrinkResources,在代码优化时会自动去掉多余资源,所以在打正式包时也不需要设置shrinkResources字段。

解决方法二:

Android Studio2.0以上有了Instant Run功能,很多情况下运行报错都跟Instant Run有关
进入File --> Setting(Ctrl+Alt+S)找到InstantRun功能,把InstantRun功能关闭





posted on 2017-05-17 14:57  竹山一叶  阅读(433)  评论(0编辑  收藏  举报