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插件默認(rèn)會(huì)啟用Manifest Merger Tool,若Library項(xiàng)目中也定義了與主項(xiàng)目相同的屬性(例如默認(rèn)生成的android:icon和android:theme),則此時(shí)會(huì)合并失敗,并報(bào)上面的錯(cuò)誤。
** 解決方法有以下2種: **
方法1: 在Manifest.xml的application標(biāo)簽下添加tools:replace="android:icon, android:theme"(多個(gè)屬性用,隔開,并且記住在manifest根標(biāo)簽上加入xmlns:tools="http://schemas.android.com/tools",否則會(huì)找不到namespace哦)
方法2: 在build.gradle根標(biāo)簽上加上useOldManifestMerger true (懶人方法)
** 參考官方介紹: **
http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger


問題2:
Android studio 升級(jí)2.2 之后 Maven插件不能使用
錯(cuò)誤信息如下:
Error:(2, 0) No service of type Factory<LoggingManagerInternal> available in ProjectScopeServices
點(diǎn)擊open file 會(huì)跳轉(zhuǎn)到配置的
apply plugin: 'com.github.dcendents.android-maven'這行。
解決方案更新maven-plugin的依賴
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
到j(luò)center查看最新版本android-maven-gradle


問題3:
錯(cuò)誤信息如下:
Error:Cannot change dependencies of configuration ':app:_debugAnnotationProcessor' after it has been
起因,在項(xiàng)目中我開啟了jack編譯器,使用了butterknife第三方工具的時(shí)候,引入了annotationProcessor,起初是沒問題的,之后我再修改編譯版本的時(shí)候,比如把BUILD_TOOLS_VERSION升到最高,然后對(duì)應(yīng)的support-v7 v4的版本也提升到相應(yīng)的版本后在運(yùn)行 就會(huì)報(bào)這個(gè)問題。
解決方案
先把引入annotationProcessor的那句話注釋掉在升級(jí)同步,之后在解開即可。


問題4:
Gradle報(bào)錯(cuò):
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名字的導(dǎo)致的,由于升級(jí)到了AS3.0后導(dǎo)致的。
原來的代碼:

    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)
            }
        }
    }

經(jīng)過查閱文檔后,修改如下:

    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
    今天把a(bǔ)ndroid studio升級(jí)到了3.1版本后突然發(fā)現(xiàn),連接上真機(jī)之后點(diǎn)擊運(yùn)行按鈕,就直接開始安裝了,少了一步編譯的過程,很是奇怪。經(jīng)過檢查發(fā)現(xiàn)原來我這筆記本上剛升級(jí)好的android studio比較奇怪,打開Run/Debug Configurations
Run/Debug Configurations

看到選中的位置,原來是少了一個(gè)Gradle-aware Make,我們點(diǎn)擊加號(hào)然后選擇gradle編譯織入就好,并且把它移動(dòng)到最上方。在此點(diǎn)擊運(yùn)行恢復(fù)正常。

PS:不定期更新

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容