Android studio我們那些年遇到的坑(一)
總結一下最近多年遇到的andorid studio重大問題,常見錯誤,另奉上處理方法
有些是查找資料看到的,有些是自己遇到的持續更新中
1、無緣無故報這個錯,Error:Protocol?family?unavailable
該錯誤很多地方都是說防火墻的問題其實不然。
參考http://bbs.csdn.net/topics/391951751?page=1
?在環境變量中增加新的變量??_JAVA_OPTIONS??
其變量值為-Djava.net.preferIPv4Stack=true???,之后重啟Android?studio就好了
2、Error?running?app:?Instant?Run?requires?'Tools?|?Android?|?Enable?ADB?integration'?to?be?enabled.
解決方案:
菜單欄,Tools -> Adnroid -> enable ADB integration
3、Error:(1,?0)?Cause:?com/android/build/gradle/LibraryPlugin?:?Unsupported?major.minor?version?52.0
這個錯誤的原因是在 工程的build.gradle
文件中的gradle 工具配置使用了gradle:+
將它
classpath 'com.Android.tools.build:gradle:+'
替換為固定版本的gradle。問題解決
?classpath "com.android.tools.build:gradle:2.1.0"
Android—那些年我們曾經遇到過的坑。。。
寫在前面的:
曾經有沒有在為引入一個lib而出現各種問題而崩潰?有沒有升級studio之后各種問題而煩惱?有沒有被一些莫名其妙的問題而困擾?
那就好好看看下面的總結吧,,,,
(1)將Eclipse項目導入到Android studio 中 很多點9圖出現問題解決方法:
在build.gradle里添加以下兩句:
aaptOptions.cruncherEnabled = false ? ?
aaptOptions.useNewCruncher = false
用來關閉Android Studio的PNG合法性檢查的,直接不讓它檢查。
(2)Android Studio 錯誤: 非法字符: '\ufeff' 解決方案|錯誤: 需要class, interface或enum
原因:
Eclipse可以智能的把UTF-8+BOM文件轉為普通的UTF-8文件,Android Studio還沒有這個功能,所以使用Android Studio編譯UTF-8+BOM編碼的文件時會出現” 非法字符: '\ufeff' “之類的錯誤
解決方法:
手動將UTF-8+BOM編碼的文件轉為普通的UTF-8文件。用EdItPlus打開.java文件依次:文檔》文本編輯》轉換文本編碼》選擇UTF-8編碼即可
(3)將項目導入到AS中出現以下問題:
Error:Execution failed for task
':app:transformResourcesWithMergeJavaResForDebug'
. > com.android.bui
解決方法:
在build.grade中添加以下代碼:
android{
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'exclude
'META-INF/NOTICE'exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'exclude 'META-INF/LICENSE.txt'
}
}
(4)未知錯誤
Error:Timeout waiting to lock cp_proj class cache for
build file '/Users/Mr.xiao/Desktop/AndroidShopNC2014Mob
lieNew/androidShopNC2014Moblie/build.gradle'
(/Users/Mr.xiao/.gradle/caches/2.10/scripts
/build_3cyr7hzjurcc62ge3ixidshos/cp_proj).
It is currently in use by another Gradle instance.
Owner PID: unknownOur PID: 1412Owner Operation:
unknownOur operation: Initialize cacheLock
file: /Users/Mr.xiao/.gradle/caches/2.10/scripts/build_3
cyr7hzjurcc62ge3ixidshos/cp_proj/cache.properties.lock
解決方案
以上是錯誤提示。
解決的思路很簡單只需要把cache.properties.lock文件刪除了就可以了。當時我們刪除的時候會被占用這時候需要進入任務管理器結束關于java的進程就行比如 java 的jdk 刪除后重啟讓java jdk啟動 ?啟動Android Studio就能啟動APK了。
(5)修改了Android項目的最小SDK版本之后出現很多stysle文件找不到
解決方案
compileSdkVersion 23buildToolsVersion "23.0.3"
defaultConfig {
applicationId "net.mmloo2014.android"minSdkVersion
14targetSdkVersion 23}
compileSdkVersion 是多少版本的
那么compile 'com.android.support:appcompat-v7:23.2.1’ 就是啥版本的。
(6)Android studio 編譯問題:finished with non-zero exit value 2 問題:
Error:Execution failed for task '
:androidShopNC2014Moblie:transformClassesWithDexForDebug'
.>com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException:
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException:
Process 'command '/Library/Java/JavaVirtualMachines/
jdk1.7.0_79.jdk/Contents/Home/bin/java''
finished with non-zero exit value 2
解決方案
這個錯誤在app的build.gradle里面添加下面這句就好了。
android {
defaultConfig {
multiDexEnabled true
? ? ?}
}
(7)Android studio 編譯問題:finished with non-zero exit value 1(由于導入的依賴出現重復造成的)
問題:
Error:Execution failed for task '
:app:transformClassesWithDexForDebug'.
> com.[Android](http://lib.csdn.net/base/15).build.api.
transform.TransformException:
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException:
Process 'command 'F:\Program Files (x86)\[Java]
(http://lib.csdn.net/base/17)\jdk1.8.0_31\bin\java.exe'
' finished with non-zero exit value 1
解決方案
這個是因為依賴包重復了 (像v4和nineoldandroids),app中實現了對easeUI的依賴,但是app和easeUI都添加了對這個包的依賴。所以就報這個錯誤,修改之后再報,就clean,rebuild一下。
(8)問題
Error:Execution failed for task
':app:transformClassesWithJarMergingForDebug'.>
com.android.build.api.transform.TransformException:
java.util.zip.ZipException:duplicate entry:
org/apache/http/ConnectionClosedException.class
解決方案
這個是在我們啟動的時候報錯的,而不是在編譯的時候,原因是這樣的,報這個錯是因為有2個庫中存在相同的類。大家可以看到stackoverflow上有人也提了這樣的問題。只需要刪除其中的一個就可以解決了。
(9)添加第三方依賴出現的問題
Error:Execution failed for task ':
app:processDebugManifest'.
>
Manifest merger failed :
uses-sdk:minSdkVersion 14 cannot be smaller than version
19 declared in library [com.github.meikoz:basic:2.0.3]
/AndroidStudioCode/EnjoyLife/app/build/intermediates/
exploded-aar/
com.github.meikoz/basic/2.0.3/AndroidManifest.xml
Suggestion: use tools:overrideLibrary="com.android.core"
to force usage
錯誤原因
出現這個錯誤的原因是我引入的第三方庫最低支持版本高于我的項目的最低支持版本,異常中的信息顯示:我的項目的最低支持版本為14,而第三方庫的最低支持版本為19,所以拋出了這個異常。
解決方案
在AndroidManifest.xml文件中標簽中添加
<uses-sdk tools:overrideLibrary="xxx.xxx.xxx"/>
其中的xxx.xxx.xxx為第三方庫包名,如果存在多個庫有此異常,則用逗號分割它們,例如:
<uses-sdk tools:overrideLibrary="xxx.xxx.aaa, xxx.xxx.bbb"/>
這樣做是為了項目中的AndroidManifest.xml和第三方庫的AndroidManifest.xml合并時可以忽略最低版本限制。
(10)Android studio 編譯問題:finished with non-zero exit value 1(由于buildtools版本太高造成的)
錯誤
Error:Execution failed for task ':app:
transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException:
Process 'command '/Library/Java/JavaVirtualMachines/
jdk1.7.0_79.jdk/Contents/Home/bin/java''
finished with non-zero exit value 1
錯誤原因
buildToolsVersion版本太高,我原來的 buildToolsVersion "24.0.0” 需要jdk1.8,而我的是jdk1.7,所以一直報這個錯,剛開始以為是v4包和V7包沖突,因為之前遇到這樣的問題,而這次刪除V4包之后依然報這個錯,上stackoverflow搜了一下,把buildTools版本降下來就好了。
解決方案
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
}
(11)Android studio 編譯問題:Gradle DSL not found 'android()'
clipboard.png
解決方案
配置build.gradle:
buildscript {
repositories { ?
jcenter()
}
dependencies { ?
classpath 'com.android.tools.build:gradle:2.1.2'
? }
}
allprojects { ?
repositories { ? ?
jcenter()
? }
}
buildscript {
repositories { ? ? ?
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
? ?}
}
allprojects {
repositories {
jcenter()
? ?}
}
配置app/build.gradle:
apply plugin: 'com.android.application'android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
minSdkVersion 9 targetSdkVersion 23 versionCode 1
versionName '1.0'
? ? ? ? ? ? }
}
dependencies {
compile 'com.android.support:appcompat-v7:23.2.1'
}
最后再同步一下sync即可。
(12)Android studio 編譯問題:Gradle DSL not found 'android()'
問題描述
Error:(51, 52) 錯誤: -source 1.6 中不支持 diamond 運算符
(請使用 -source 7 或更高版本以啟用 diamond 運算符)
解決方案
方案一
將標紅處設置為1.7.png
修改soure為1.7.png
方案二
在build gradle中進行配置如下代碼:
android {
compileOptions {sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
最后同步一下即可
(13)Android studio Build時沒問題就是Run不起來。
問題描述:尤其是在加入一些依賴之后,這時build可以就表示 compile一些libs已經生成了sdk,但是run得時候 AS走了自己的緩存,導致運行上次錯誤的緩存的,這時候無論怎么clean、rebuild等都是沒有效果的,因為AS的緩存一直存在。。。。
解決方案:這時候只有重啟AS清除緩存之后重新run就好了,極端的情況下,重啟電腦也是不錯的選擇。關于AS緩存問題稍后會作詳細總結。。。
快速編輯模式去掉
File Setting instant Run
(13)Android studio 從java 1.7修改至1.8導致的bug。
使用androidstudio2.2.0編譯提出需要java.
Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.
原因:
2016 年 3 月 10 日, Google 向外界發布了 Android N 的預覽版,并宣布了 Android N 的?Roadmap?,Android N 的最終版源代碼將于今年 8 或 9 月份釋出到 AOSP 項目。
在眾多的 Android N 新特性中,有一項新工具鏈的出現與 Android 生態圈的所有開發者息息相關,即 Jack & Jill 編譯器的引入。在依賴了 Sun/Oracle 的 Java 編譯器十年之后,Jack 是 Java Android Compiler Kit 的縮寫,它可以將 Java 代碼直接編譯為 Dalvik 字節碼,并負責 Minification, Obfuscation, Repackaging, Multidexing, Incremental compilation。它試圖取代 javac/dx/proguard/jarjar/multidex 庫等工具。
Android 終于有了自己的 Java 編譯器。Android7.0(API24)在對JAVA8的支持上,需要使用新的編譯器。
解決方法:
defaultConfig {
? ? ? ? applicationId "com.xxx"
? ? ? ? minSdkVersion 19
? ? ? ? targetSdkVersion 24
? ? ? ? versionCode 1
? ? ? ? versionName "1.0"
? ? ? ??jackOptions {
? ? ? ? ? ? enabled true
? ? ? ? }
}
在defaultConfig中添加紅色部分即可
(14)下載不了?
Error:Failed to open zip file.
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
Re-download dependencies and sync project (requires network)
解決這個問題的辦法有好幾個:
1.可以把gradle-wrapper.properties里修改了gradle的版本,與之前沒有報錯的gradle版本一致,然后再修改項目build.gradle文件中的com.android.tools.build:gradle的版本號,具體是多少也是參照以前那些沒有報錯的項目。
2.直接在網上找到gradle-3.3-all.zip下載下來,不要解壓縮,放在類似下面的目錄中?C:\Users\Administrator\.gradle\wrapper\dists\gradle-3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9,這個辦法沒有試過,按理說是可以的。下載地址在這里找:http://services.gradle.org/distributions/?,里面各個版本都有。
3. 最簡單的方法,也是我采用的方法,就是改一下gradle-wrapper.properties中的distributionUrl
將
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
改成
distributionUrl=http\://services.gradle.org/distributions/gradle-3.3-all.zip
以上都解決不了的話就直接把項目的的gradle文件夾刪掉重新try
(15)將Eclipse項目導入到Android studio 中 很多點9圖出現問題解決方法:
在build.gradle里添加以下兩句:
aaptOptions.cruncherEnabled = false? ?
aaptOptions.useNewCruncher = false
用來關閉Android Studio的PNG合法性檢查的,直接不讓它檢查。
(16)Android Studio 錯誤: 非法字符: '\ufeff' 解決方案|錯誤: 需要class, interface或enum
原因:
Eclipse可以智能的把UTF-8+BOM文件轉為普通的UTF-8文件,Android Studio還沒有這個功能,所以使用Android Studio編譯UTF-8+BOM編碼的文件時會出現”非法字符: '\ufeff' “之類的錯誤
解決方法:
手動將UTF-8+BOM編碼的文件轉為普通的UTF-8文件。**
**用EdItPlus打開.java文件依次:文檔》文本編輯》轉換文本編碼》選擇UTF-8編碼即可
(3)將項目導入到AS中出現以下問題:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.bui
解決方法:
在build.grade中添加以下代碼:
android{
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
? ? ? ? ? }
}
(17)未知錯誤
Error:Timeout waiting to lock cp_proj class cache for build file '/Users/Mr.xiao/Desktop/AndroidShopNC2014MoblieNew/androidShopNC2014Moblie/build.gradle'
(/Users/Mr.xiao/.gradle/caches/2.10/scripts/build_3cyr7hzjurcc62ge3ixidshos/cp_proj).
It is currently in use by another Gradle instance.
Owner PID: unknown
Our PID: 1412
Owner Operation: unknown
Our operation: Initialize cache
Lock file: /Users/Mr.xiao/.gradle/caches/2.10/scripts/build_3cyr7hzjurcc62ge3ixidshos/cp_proj/cache.properties.lock
解決方案
以上是錯誤提示。
解決的思路很簡單只需要把cache.properties.lock文件刪除了就可以了。當時我們刪除的時候會被占用這時候需要進入任務管理器結束關于java的進程就行比如 java 的jdk 刪除后重啟讓java jdk啟動? 啟動Android Studio就能啟動APK了。
(18)修改了Android項目的最小SDK版本之后出現很多stysle文件找不到
解決方案
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "net.mmloo2014.android"
minSdkVersion 14
targetSdkVersion 23
}
compileSdkVersion 是多少版本的
那么compile 'com.android.support:appcompat-v7:23.2.1’ 就是啥版本的。
(19)Android studio 編譯問題:finished with non-zero exit value 2
問題:
Error:Execution failed for task ':androidShopNC2014Moblie:transformClassesWithDexForDebug'.
>
com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException:
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException:
Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
解決方案
這個錯誤在app的build.gradle里面添加下面這句就好了。
android {
defaultConfig {
multiDexEnabled true
? ? ? }
}
(20)Failed to finalize session : INSTALL_FAILED_INTERNAL_ERROR
? ? Session 'app': Error Installing APKs
網上解決方案不一, 對自己有用的方案如下:
“File”-->“Settings”-->“Build, Exexution,Deployment”-->“Instant Run”
將如下勾選框去掉,確定,
(21)Error:Please select Android SDK
解決方法:
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
.iml文件里面
加入上面這行
(22)Error:This?Gradle?plugin?requires?Studio?3.0?minimum
Android studio版本太低,導入的項目版本高其實也就是Gradle從高版本導入到低版本里面了
?今天遇到了一個Error:This Gradle plugin requires Studio 3.0 minimum這樣的問題,我覺得是我的studio的版本不夠高,我的studio是2.3.3版本的,導入的項目的版本應該是3.0的,其實我們可以這樣,將以下內容添加到gradle.properties中:
解決方法:
1.升級現有的Android studio
2.其實我們可以這樣,將以下內容添加到gradle.properties中:android.injected.build.model.only.versioned = 3
*****************************************************
最近一直想將自己編寫程序時遇到的錯誤總結一下,但因為諸多原因一直都沒付諸行動。這個錯誤總結本人將會不斷更新,以下錯誤是本人遇到并解決了,編程工具Android studio 2.0。
錯誤提示一:
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Administrator\AppData\Local\Android\sdk1\build-tools\23.0.3\aapt.exe'' finished with non-zero exit value 1
問題描述及解決辦法:如果你只改動了程序的某個小的部分,但是報這個錯,只要點擊Build->clear project就可以解決。
錯誤提示二:
Error:A problem occurred configuring project ':app'.> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.? > Could not find com.android.support:appcompat-v7:23.4.0.? ? Required by:
? ? ? ? xcmg:app:unspecified
? > Could not find com.google.android.gms:play-services-appindexing:8.1.0.? ? Required by:
? ? ? ? xcmg:app:unspecified
? > Could not find com.android.support:support-v4:23.4.0.? ? Required by:
? ? ? ? xcmg:app:unspecified
問題描述及解決辦法:如果你是導入新的已存在的代碼,按如下步驟可解決問題(這是本人遇到的問題,不一定適合所有此類問題)?
步驟1?
點擊SDK Manager——>SDK Tools 勾選google respository——>apply然后跟著提示走即可。?
步驟2:上述步驟完成后,再點擊Build——>clean project即可
錯誤提示三:
Error:A problem occurred configuring project ':app'.> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.? > Could not find com.android.support:appcompat-v7:23.4.0.? ? Required by:
? ? ? ? xcmg:app:unspecified
? > Could not find com.android.support:support-v4:23.4.0.? ? Required by:
? ? ? ? xcmg:app:unspecified
? > Could not find com.android.support:support-v4:23.4.0.? ? Required by:
? ? ? ? xcmg:app:unspecified > com.google.android.gms:play-services-appindexing:8.1.0 > com.google.android.gms:play-services-basement:8.1.0
問題描述及解決辦法:如果你是導入新的已存在的代碼,按如下步驟可解決問題(這是本人遇到的問題,不一定適合所有此類問題)?
步驟1?
點擊SDK Manager——>SDK Tools 勾選android support respository——>apply然后跟著提示走即可。?
步驟2?
上述步驟完成后,再點擊Build——>clean project即可
錯誤提示四
Error:(1, 0) Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to "e0a7992f192675817297767391b8206ce7252324"<a href="fixGradleElements">Fix plugin version and sync project</a><br><a href="openFile:F:\Androidstudio\ListViewDemo\app\build.gradle">Open File</a>
問題描述及解決辦法:如果你是在導入一個包時出現這個問題,那么按以下步驟來修改。
步驟一:打開build.gradle,找到classpath,如圖
是這里的classpath值不對,那么,怎么設置這里的值呢?
步驟二:File——>project structure?
步驟三:project——>將android plugin version里的內容寫入步驟一的classpath里。
步驟四:上述步驟完成后,再點擊Build——>clean project即可?
(未完待續……)
錯誤提示五?
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
解決方案:在工程的混淆配置文件 proguard-rules.pro 中加入下面這句代碼即可:?
-keepattributes EnclosingMethod
錯誤提示六?
All packages are not available for download!The following packages are not available:-Package id platforms;android-1?
解決方案:抽出數據線然后重新插上。嗯,不要問我為什么,我就是這樣解決的。
錯誤提示七?
Error:(16, 0) Could not find method android() for arguments
解決方案:在工程的最外層的build.gradle文件里刪除android{}
問題提示八?
Could not find method compile() for arguments
解決方案:在工程的最外層的build.gradle文件里的dependencies刪除complie內容。然后rebuild project和clean project.?
問題提示九:
Error:Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at https://docs.gradle.org/3.3/userguide/gradle_daemon.htmlPlease read the following process output to find out more:-----------------------Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap
Java HotSpot(TM) Client VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
解決方案一:在gradle.properties里添加
org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8org.gradle.parallel=true
解決方案二:在C:\Users\yds(當前電腦用戶名).gradle(如果沒有新建)gradle.properties 文件里寫下:
org.gradle.jvmargs=-Xmx1024m
錯誤提示十
android.view.InflateException: Binary XML file line #243: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
解決方案:布局文件中寫了個view(布局文件中我寫的v為小寫,應該大寫),改為View就行了。
錯誤提示十一:Failed to create jvm:error code -6
解決方案:在C:\Users\xxx(這里是電腦用戶名,沒有就是Admination).AndroidStudioxx.xx目錄下刪除studio.exe.vmoptions
錯誤提示十二:
android.content.res.Resources$NotFoundException: String resource ID #0x2
解決方案:當調用setText()方法時如果傳入int型是不會被當成內容而是resourceID來使用!所以把int轉成字符串類型
錯誤提示十三:
當使用NagivationView時報錯:java.lang.reflect.InvocationTargetException
解決方案:(1)將Activity(入口Activity)寫成CompatActivity;(2)將Manifest里將該Activity的theme改為@style/Theme.AppCompat的主題。
錯誤提示十四:
Error:(1, 1) A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
? > Could not create plugin of type 'AppPlugin'.
解決方案:是build.grade文件出問題,問題如下:?
替換成如下所示?
然后clear project
錯誤十四
No such property: FOR_RUNTIME for class: org.gradle.api.attributes.Usage
自從Android studio升級到3.1版本,谷歌又折騰出讓你意想不到的錯誤。。。。
從github上下了個項目用來學習,卻出現了如下錯誤:
1No such property: FOR_RUNTIME?for?class: org.gradle.api.attributes.Usage
?在網上搜索到的解決方法大都是讓把Gradle降級,但是新版本的AS最低Gradle版本是4.4,沒有辦法降級,這就讓人頭疼了。
查了很久,才找到解決辦法:
產生這個問題的原因是項目中導入的一個module使用了bintray插件導致的,在module的build.gradle文件中將bintray相關代碼注釋掉,之后進行編譯,有可能會報其他錯誤,這個時候就繼續刪錯誤指向的語句,之后便能正常運行。
錯誤十五
今天在使用科大訊飛語音識別SDK進行語音識別功能實現時,莫名的引入了這個錯誤。不得不吐槽Android Studio再引入別的包時太容易出現沖突,然后導致無法找到R文件,項目無法執行。
1. 具體報錯
app/build/intermediates/res/merged/debug/values-v28/values-v28.xml Error:(7, 41) No resource found that matches the given name (at 'dialogCornerRadius' with value '?android:attr/dialogCornerRadius').
...
Error:Execution failed for task ':app:processDebugResources'. com.android.ide.common.process.ProcessException: Failed to execute aapt
2. 報錯原因
在build項目時默認使用了values-v28下的style.xml,但無法找到與該style.xml相匹配的資源
3. 解決辦法
修改build.gradle文件,取消動態依賴,指定特定版本的依賴
PS:最好將所有引用的包都改成同一版本的依賴
修改前:
compileSdkVersion 26buildToolsVersion '26.0.2'targetSdkVersion 26compile 'com.android.support:recyclerview-v7:+'compile 'com.android.support:appcompat-v7:+'
修改后:
compileSdkVersion 26buildToolsVersion '26.0.2'targetSdkVersion 26compile 'com.android.support:recyclerview-v7:26.0.2'compile 'com.android.support:appcompat-v7:26.0.2'
使用“+”時,會自動使用最新版本的values進行build,所以最好指定SDK的版本,避免不必要的錯誤
當項目編譯不過的時候可以嘗試以下方法
遇鑒問題修復記錄
Android Studio and Gradle are using different locations for the JDK.
Android Studio: D:\RDTool\Android\Studio\jre
Gradle: C:\Program Files\Java\jdk1.8.0_191
Using different JDK locations might cause Gradle to spawn multiple daemons
when executing tasks for Android Studio and other external processes.
在Android studio升級后,打開好久沒打開的項目打包,突然就報這個錯誤了,一直打包失敗
gradle的版本是
gradle-5.1.1-all.zip
百度都是clear和build,完全沒有用。
最后發現Event log有個提示
Android Studio is using this JDK location:
?? ??? ??? ?D:\Android\Android Studio\jre
?? ??? ??? ?which is different to what Gradle uses by default:
?? ??? ??? ?C:\java\jdk1.8.0_101
?? ??? ??? ?Using different locations may spawn multiple Gradle daemons if
?? ??? ??? ?Gradle tasks are run from command line while using Android Studio.
?? ??? ??? ?More info...
?? ??? ??? ?Set Android Studio to use the same JDK as Gradle and sync project
?? ??? ??? ?Do not show this warning again
原來是我的jdk配置被改掉了。。。。。
最后選擇Set Android Studio to use the same JDK as Gradle and sync project
設置一下jdk就可以成功打包了
Unable to load class 'org.gradle.api.internal.component.Usage'
我的運行環境:
Ubuntu16.04系統
Android Studio 3.0 版本
下載https://github.com/JessYanCoding/ProgressManager示例后,在工程的build.gradle里面修該成我本地的版本如下:
在編譯的時候就出現了以下錯誤:
Error:Unable to load class 'org.gradle.api.internal.component.Usage'.
Possible causes for this unexpected error include:
? Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
? Re-download dependencies and sync project (requires network)
? The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
? Stop Gradle build processes (requires restart)
? Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
解決
這是由于插件兼容問題導致的錯誤,如果有com.novoda:bintray-release請把版本修改為0.5.0。
感謝weixin_41101173的提示,對于大于AndroidStudio3.14版本的,請改為0.8.0
再次編譯就ok了。
解決Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
這個問題是Android studio升級到3.0之后,運行的時候會提示gradle要升級到3.5版本才能編譯。于是我把我的gradle升級到了
?gradle-4.1-milestone-1 版本,是2017年7月份最新版本了。
于是我把主程序的build.gradle中的gradle版本改成了這個,具體指定哪個版本我也不知道,于是就寫了個3.0+
?dependencies?{
????????classpath?'com.android.tools.build:gradle:3.0+'?
}
然后再次編譯,又發現了毒。
提示:Error:All flavors must now belong to a named flavor dimension.Learn?more?at?https://d.android.com/r/tools/flavorDimensions-missing-error-message.html?
這個一個錯誤,意思是:所有的flavors都必須屬于同一個風格。
=。=懵逼
去翻墻看了它提供的地址才知道:
?Plugin?3.0.0?includes?a?new?dependency?mechanism?that?automatically?matches?variants?when?consuming?a?library.?This?means?an?app's?debug?variant?automatically?consumes?a?library's?debug?variant,?and?so?on.?It?also?works?when?using?flavors—an?app's?redDebug?variant?will?consume?a?library's?redDebug?variant.?To?make?this?work,?the?plugin?now?requires?that?all?flavors?belong?to?a?named?flavor?dimension?—even?if?you?intend?to?use?only?a?single?dimension.?Otherwise,?you?will?get?the?following?build?error:
Error:All flavors must now belong to a named flavor dimension.
The flavor 'flavor_name' is not assigned to a flavor dimension.
?To?resolve?this?error,?assign?each?flavor?to?a?named?dimension,?as?shown?in?the?sample?below.?Because?dependency?matching?is?now?taken?care?of?by?the?plugin,?you?should?name?your?flavor?dimensions?carefully.?For?example,?if?all?your?app?and?library?modules?use?the?foo?dimension,?you'll?have?less?control?over?which?flavors?are?matched?by?the?plugin.?
// Specifies a flavor dimension.
flavorDimensions "color"
productFlavors {
? ? red {
? ? ? // Assigns this product flavor to the 'color' flavor dimension.
? ? ? // This step is optional if you are using only one dimension.
? ? ? dimension "color"
? ? ? ...
? ? }
? ? blue {
? ? ? dimension "color"
? ? ? ...
? ? }
}
大致是說,Plugin?3.0.0之后有一種自動匹配消耗庫的機制,便于debug variant?自動消耗一個庫,然后就是必須要所有的flavor 都屬于同一個維度。
為了避免flavor 不同產生誤差的問題,應該在所有的庫模塊都使用同一個foo尺寸。
= 。=還是懵逼。說一堆依然不是很理解。
但是我們從中已經知道解決方案了:
在主app的build.gradle里面的
?defaultConfig {
?targetSdkVersion:***
minSdkVersion :***
versionCode:***
?versionName :***
//版本名后面添加一句話,意思就是flavor?dimension 它的維度就是該版本號,這樣維度就是都是統一的了
flavorDimensions "versionCode"
示例
flavorDimensions "default"
}
就直接解決這個問題。然后app 就可以happy的運行起來了。
解決Error:All flavors must now belong to a named flavor dimension. Learn more at...
低版本的gradle里面不會出現這個錯誤,高版本出現,不多說,看如何解決
在defaultConfig{}中添加:
flavorDimensions "default"
保證所有的flavor 都屬于同一個維度
defaultConfig {? ? ? ? applicationId "com.status.channel"? ? ? ? minSdkVersion 15? ? ? ? targetSdkVersion 28? ? ? ? versionCode 1? ? ? ? versionName "1.0"? ? ? ? testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"? ? ? ? flavorDimensions "default"? ? }
How to Fix Error:(59, 8) error: cannot access ActivityCompatApi23 class file for android.support.v4.app.ActivityCompatApi23 not found
或者
Cannot access android.support.ActivityCompatApi23.RequestPermissionsRequestCodeVa;odator
不同的版本所致的可以使用下面這個解決方案
Code to fix?cannot access ActivityCompatApi23 in Android Studio
configurations.all {
? ? resolutionStrategy.eachDependency { DependencyResolveDetails details ->
? ? ? ? def requested = details.requested
? ? ? ? if (requested.group == 'com.android.support') {
? ? ? ? ? ? if (!requested.name.startsWith("multidex")) {
? ? ? ? ? ? ? ? details.useVersion '25.3.0'
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
關于 '@android:attr/windowEnterAnimation' not found.的問題(解決)
問題描述:準備要寫個dialog展示和隱藏的動畫,很小的一個動畫就可以解決,但是寫的過程中遇到了這個error: style attribute '@android:attr/windowEnterAnimation' not found.這個問題,菜雞的我,立即開始百度,看了很多,綜合一下,有2種解決方案
1.把@去掉,因為已經不支持@開頭的 android自帶屬性了
2.在gradle.properties 中添加android.enableAapt2=false? 因為默認Aapt是開啟的(不知道你們理解不,反正我是不知道Aapt是啥)
我先嘗試了第一種方法,發現沒有效果,還是報錯,而且看到網上有人和我一樣情況,我就確定這個確定不管用,于是我就嘗試了第二種方法
成功了,這個問題就這樣被我解決了
事實并不是這樣,等第二天我來到公司的時候,在運行項目報錯了?
這個問題把我難住了,菜雞的我還是直接百度,但是這次百度啥也沒說,說是增強for使用的時候出錯了,我擦,我沒用呀,重點是我這邊沒有日志,就這一條,苦逼的我,下載了最新版的as,這次錯誤信息出來了,結果就是因為加了android.enableAapt2=false? 這句話導致的,沒辦法只能刪了這句話,最后我全局搜了一下@android:attr/windowEnterAnimation 這個,發現其他地方沒改,我改了之后項目沒毛病了,還是第一種解決方案是對的
粗心大意的我。。。
C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\appcompat-v7-26.1.0.aar\6a8b09efde42f84982ba083742b4753d\res\values\values.xml
Error:(1050, 5) error: resource style/Widget.AppCompat.DrawerArrowToggle (aka com.wcyq.wolfmvvmdemo:style/Widget.AppCompat.DrawerArrowToggle) not found.
Error:(862, 5) error: resource style/Widget.AppCompat.DrawerArrowToggle (aka com.wcyq.wolfmvvmdemo:style/Widget.AppCompat.DrawerArrowToggle) not found.
1.http://blog.csdn.net/qq_33337504/article/details/79129625
? ? 在gradle.properties 文件下添加?android.enableAapt2=false
2.http://blog.csdn.net/lyc088456/article/details/79011385?
? ?在AS 的左上角 選擇 -->File-->invalidated and Restart 一下
操作了,沒解決我的問題.
一時間搞得很煩躁.后來自己改了下依賴版本號,結果就好了,操
沒改之前; 這個是studio自動生成的.
dependencies {
? ? implementation fileTree(dir: 'libs', include: ['*.jar'])
? ? implementation 'com.android.support:appcompat-<span style="color:#ff0000;">v7:26.+'</span>
? ? implementation 'com.android.support.constraint:constraint-layout:1.0.2'
? ? testImplementation 'junit:junit:4.12'
? ? androidTestImplementation 'com.android.support.test:runner:1.0.1'
? ? androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
改了之后;
dependencies {
? ? implementation fileTree(dir: 'libs', include: ['*.jar'])
? ? implementation 'com.android.support:appcompat-v<span>7:25.+</span>'
? ? implementation 'com.android.support.constraint:constraint-layout:1.0.2'
? ? testImplementation 'junit:junit:4.12'
? ? androidTestImplementation 'com.android.support.test:runner:1.0.1'
? ? androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
?程序能跑起來了.真是斃了狗了,studio一升級,盡是些狗屁問題,建議沒有升級的還是不要升級這些新版本,問題搞的頭大!
27.Android app運行到vivo手機上是彈出安裝失敗,安裝包損壞。
我的解決方法是在 項目的 gradle.properties中加入一行這個代碼,重新運行即可解決運行安裝失敗的問題。
android.injected.testOnly = false
28.Androidstudio 運行app安裝失敗
該方法慎用
未完待續