Android Studio中遇到的一些问题

问题1:

Error:(26, 9) Attribute application@icon value=(@drawable/logo) from AndroidManifest.xml:26:9
Error:(28, 9) Attribute application@theme value=(@style/ThemeActionBar) from AndroidManifest.xml:28:9
is also present at XXXX-trunk:XXXXLib:unspecified:15:9 value=(@style/AppTheme)
Suggestion: add ‘tools:replace=”android:theme”‘ to <application> element at AndroidManifest.xml:24:5 to override
Error:Execution failed for task ‘:XXXX:processDebugManifest’.
Manifest merger failed with multiple errors, see logs

** 原因: **
AS的Gradle插件默认会启用Manifest Merger Tool,若Library项目中也定义了与主项目相同的属性(例如默认生成的android:icon和android:theme),则此时会合并失败,并报上面的错误。
** 解决方法有以下2种: **
方法1: 在Manifest.xml的application标签下添加tools:replace=”android:icon, android:theme”(多个属性用,隔开,并且记住在manifest根标签上加入xmlns:tools=”http://schemas.android.com/tools“,否则会找不到namespace哦)
方法2: 在build.gradle根标签上加上useOldManifestMerger true (懒人方法)
** 参考官方介绍: **
http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger

问题2:
Android studio 升级2.2 之后 Maven插件不能使用
错误信息如下:
Error:(2, 0) No service of type Factory<LoggingManagerInternal> available in ProjectScopeServices
点击open file 会跳转到配置的
apply plugin: 'com.github.dcendents.android-maven'这行。
解决方案更新maven-plugin的依赖
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
到jcenter查看最新版本android-maven-gradle

问题3:
错误信息如下:
Error:Cannot change dependencies of configuration ‘:app:_debugAnnotationProcessor’ after it has been
起因,在项目中我开启了jack编译器,使用了butterknife第三方工具的时候,引入了annotationProcessor,起初是没问题的,之后我再修改编译版本的时候,比如把BUILD_TOOLS_VERSION升到最高,然后对应的support-v7 v4的版本也提升到相应的版本后在运行 就会报这个问题。
解决方案
先把引入annotationProcessor的那句话注释掉在升级同步,之后在解开即可。

问题4:
Gradle报错:
Cannot set the value of read-only property ‘outputFile’ for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=commonDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
原因在于我在gradle文件中加入了打包apk并直接自定义修改apk名字的导致的,由于升级到了AS3.0后导致的。
原来的代码:

    applicationVariants.all { variant ->
        variant.outputs.each {output->
            def outputFile=output.outputFile
            if(outputFile!=null && outputFile.name.endsWith(".apk")){
                def name=outputFile.name.replace("app",variant.getVersionName())
                output.outputFile=new File(outputFile.parent,name)
            }
        }
    }

经过查阅文档后,修改如下:

    applicationVariants.all { variant ->
        variant.outputs.all {output->
            def outputFile=output.outputFile
            if(outputFile!=null && outputFile.name.endsWith(".apk")){
                outputFileName=outputFile.name.replace("app",variant.getVersionName())
            }
        }
    }

原因:

// If you use each() to iterate through the variant objects,
// you need to start using all(). That's because each() iterates
// through only the objects that already exist during configuration time—
// but those object don't exist at configuration time with the new model.
// However, all() adapts to the new model by picking up object as they are
// added during execution.
  • 问题5
    今天把android studio升级到了3.1版本后突然发现,连接上真机之后点击运行按钮,就直接开始安装了,少了一步编译的过程,很是奇怪。经过检查发现原来我这笔记本上刚升级好的android studio比较奇怪,打开Run/Debug Configurations

《Android Studio中遇到的一些问题》 Run/Debug Configurations

看到选中的位置,原来是少了一个Gradle-aware Make,我们点击加号然后选择gradle编译织入就好,并且把它移动到最上方。在此点击运行恢复正常。

PS:不定期更新

    原文作者:Ggx的代码之旅
    原文地址: https://www.jianshu.com/p/4f04832e01a7
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞