Android Studio导入公司之前Eclipse项目的一些异常处理和注意事项。

最近,几年前的一个app客户反应有点小bug。顿时觉得,都几年了,app还有必要改吗?硬件部门的老大告诉我,这客户的硬件产品在海外每年数百万的销量。顿时,哑口无语。
之前的项目是用Eclipse开发的。有强迫症的自己,硬是要转到Android Studio上。异常不少,不过还好,能运行。这里分享一下Eclipse转到AS上的一些异常。

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

Android Studio导入公司之前Eclipse项目的一些异常处理和注意事项。_第1张图片
依赖.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
}

好了,就这么多了。

你可能感兴趣的:(Android Studio导入公司之前Eclipse项目的一些异常处理和注意事项。)