Android

升級後,想說試試官方的 Samples

Android Studio 3.1.3 編譯 AppUsageStatistics Sample

https://github.com/googlesamples/android-AppUsageStatistics/#readme

結果 error 滿天飛

這些錯誤訊息都沒有幫助,甚至有誤導之嫌.....

找了三天,原來是 build.gradle 裡面

dependencies {

compile 'com.android.support:support-v4:27.0.2'
compile 'com.android.support:support-v13:27.0.2'
compile 'com.android.support:cardview-v7:27.0.2'
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:appcompat-v7:21.+'
}

改成.....

dependencies {
    implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support:support-v13:27.0.2'
implementation 'com.android.support:cardview-v7:27.0.2'
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
}

版本號碼不要用 "+",就沒 error
compile 改成 implementation 可以去除警告訊息

感謝這篇最後有個高手提示
https://stackoverflow.com/questions/50266035/no-resource-identifier-found-for-attribute-appcomponentfactory-in-package-and
要不然,依照錯誤訊息找到的文章大部分都要你關閉 AAPT2,雖然真的減少一兩個報錯,可是卻使問題更難找了,
而且,關閉這個新的資源編譯器,對未來開發很不利阿!!

在Android Studio App Project 加入 Google Maps Activity 遇到執行錯誤,在 Gradle Console 訊息如下:

:app:transformClassesWithDexForDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536


 

Google 老半天,有的說程式需要減肥,有的是Android Studio Invalidate Caches 需要清乾淨,或是有人 clean project......不過,還是比較多人提到版本衝突問題:

試了老半天,在Build.Grandle 找到這一段,修改後有效:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
compile 'com.google.android.gms:play-services:9.8.0'
testCompile 'junit:junit:4.12'
}

把這兩列改為:

compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'com.google.android.gms:play-services:8.1.0'

這樣就能順利執行,至於Google Service 版本號碼,可以搜尋 google play service previous versions

 
Go to top