Android Studio導入公司之前Eclipse項目的一些異常處理和注意事項。

最近,幾年前的一個app客戶反應有點小bug。頓時覺得,都幾年了,app還有必要改嗎?硬件部門的老大告訴我,這客戶的硬件產品在海外每年數百萬的銷量。頓時,啞口無語。
之前的項目是用Eclipse開發的。有強迫癥的自己,硬是要轉到Android Studio上。異常不少,不過還好,能運行。這里分享一下Eclipse轉到AS上的一些異常。

1.去掉project.properties中的依賴包。

依賴.png

2.除了 android-support-v7-appcompat可以直接在build.gradle 添加依賴外。別的,就只能使用import module了。這個就不詳細說步驟了。太簡單了。

3.異常1:
Error:Application and test application id cannot be the same: both are 'com......' for debugAndroidTest
刪掉build.gradle里面defaultConfig的配置文件:
defaultConfig {
……
/* testApplicationId "com.cheerchip.aurazero"
testInstrumentationRunner "android.test.InstrumentationTestRunner"*/
}

4.異常2.
Error:Error: '.' is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore
核心意思就是命名不規范,多了一個.,我一看卻是是一個圖片名字里面帶了一點".",這里也請留意:names must contain only lowercase a-z, 0-9, or underscore
Andriod Studio命名就是這樣要求的。

5.異常:Error:(4) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
將compileSdkVersion版本要么降低,要么設置和現在Andriod Studio其他的項目一樣。

6.異常3:
顯示服務的問題:Android 5.0的service服務必須采用顯示方式啟動。而之前是用隱示服務。查看Android 源碼:
android源碼:(源碼位置:sdk/sources/android-21/android/app/ContextImpl.java):
private void validateServiceIntent(Intent service) {
if (service.getComponent() == null && service.getPackage() == null) {
if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.LOLLIPOP) {
IllegalArgumentException ex = new IllegalArgumentException(
"Service Intent must be explicit: " + service);
throw ex;
} else {
Log.w(TAG, "Implicit intents with startService are not safe: " + service
+ " " + Debug.getCallers(2, 3));
}
}
}

解決辦法:
Intent mIntent = new Intent();
mIntent.setAction("XXX.XXX.XXX");//你定義的service的action
mIntent.setPackage(getPackageName());//這里你需要設置你應用的包名
context.startService(mIntent);

7.The same input jar is specified twice
原因是:原因是build.gradle文件配置了
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
}
已經添加jar,記得把混淆文件里proguard.cfg對-libraryjars的注釋去掉。

8.記得忽略檢查,不然總是打包失敗。
lintOptions{
checkReleaseBuilds false
abortOnError false
}

好了,就這么多了。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容