Android 編譯時異常

1. Apostrophe not preceded by \ XXX

某些字符未被轉義,我遇到的是 ’ 沒有轉譯,寫成\’ ok。

2. CMake was unable to find a build program corresponding to “Ninja”

今日導入了別人寫的Native項目,報了這個錯:

CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.

錯誤很明顯,是說找不到Ninja。因此只要給添加上就OK了。

  1. 下載Ninja https://github.com/ninja-build/ninja/releases
  2. 解壓後放入 /usr/bin/
    問題解決

3. More than one file was found with OS independent path

在出錯的Model的gradle的android節點下添加

packagingOptions {
        pickFirst 'META-INF/*'
    }

4. has different version for the compile (1.1.0) and runtime (1.1.1) classpath

字面意思編譯版本和運行版本不一致,造成整個問題是由於依賴包衝突,我們可以通過以下命令查看項目的依賴關係:

./gradlew app:dependencies > log_dependencies.txt

這樣依賴關係會保存到項目下的log_dependencies.txt文件內,在文件裏搜索衝突的依賴包,然後進行excule即可。我的項目發生這個問題是在引入room數據庫後發生了android.arch.core:runtime這個包的衝突。排查發現com.android.support:design中用到了這個庫,解決如下:

implementation ('com.android.support:design:27.1.0'){
        exclude(group: 'android.arch.core', module: 'runtime')
    }

5. cannot access RoomDatabase

出現這個問題是由於我將一個帶有Room的模塊單獨打成了一個module,在主項目引入該module。解決方法:
在之前的module中引入Room的方式由implementation改爲api

6. Cannot add task ‘install’ as a task with that name already exists

可能大家遇到的不是install,而是其他的任務,但思想應該是一致的。我出現這個問題是這樣的:我寫了一個依賴庫,開始時候是用apply plugin: 'maven’發佈到本地,後來又想發佈到網絡倉庫添加了apply plugin: 'com.github.dcendents.android-maven’這兩個插件都使用了install這個task,所以造成了衝突,去掉一個就ok了

7. You must specify a URL for a Maven repository

有點丟人,maven配置時候多了一層嵌套。。。
錯誤寫法

maven{
	maven { url 'https://jitpack.io' }
}

去除外層的maven{}解決

發佈了42 篇原創文章 · 獲贊 6 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章