天天看點

Android開發中的問題集合

AndroidStudio更新到3.6之後有各種問題,這裡就一點點收集,之前也有這個想法但是沒有寫出來,今天趁着隔離期間整理一下.

1.The given artifact contains a string literal with a package reference 'android.support.v4.content' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.

截圖如下:

Android開發中的問題集合

問題描述:

(1).我的 Android 項目采用的是 AndroidX;

(2).我首先使用的是butterknife 8.58.1版本,報錯,提示我用butterknife 9.0 以上;

(3).我使用butterknife 9.0,繼續報上面的錯誤;

(4).解決方法:我更新到最新的butterknife 10.2.1 即可.

修改後重新運作項目,可以看到下圖項目運作成功:

Android開發中的問題集合

2.項目運作時報錯,錯誤資訊如下:java.lang.BootstrapMethodError: Exception from call site #1 bootstrap method

Android開發中的問題集合

 錯誤原因:項目中同時使用了butterknife和view這2中方式進行視圖綁定時,addIv.setOnClickListener(v ->{})使用了java8新特性.

View view = inflater.inflate(R.layout.dialog_add_cart, null);
@BindView(R.id.tv_day)
TextView tvDay;
           
Android開發中的問題集合

解決方法:

build.gradle中添加以下代碼:

compileOptions{
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
           

重新編譯項目發現問題已經解決!未完待續,後面收集到新的問題會及時更新.

繼續閱讀