Eclipse中的项目迁移到Android Studio填坑

首先从Eclipse中导出Gradle文件,再将项目导入Android Studio中。

1、文件编码的错误:

Error:(1, 1) 错误: 非法字符: \65279
Error:(1, 10) 错误: 需要class, interface或enum

文件中的编码有错误,可以将整个文件的内容先复制下来(Ctrl+c),然后从项目中删除文件,并建立同名的文件,并将内容粘贴过去(Ctrl+v)。

2、删除Module后,如果出现:

Failed to complete Gradle execution. Cause: Already disposed: Module: 'XX'

解决方法

1、./gradlew clean
2、Restart Android stduio

3、导入后的文件提示

Android Studio “This file is indented with tabs instead of 4 spaces”
Any of the following will work:
Uncheck the Detect and use existing file indents for editing setting.

解决方法

Change your default indenting for Java (not just on the general Code Style page). Go to File > Settings > Editor > Code Style > Java. On the Tabs and Indents tab click "Use tab character".

4、Android Studio编译时Gradle报乱码: “编码 UTF-8 的不可映射字符”

tasks.withType(Compile) {  
    options.encoding = "UTF-8"  
}  

 但是这个配置在gradle2.0以前是可以生效的,在gradle2.0以后就不能生效了,原因是Compile已经被重命名为JavaCompile。所以在gradle2.0以后需要添加的配置如下:

tasks.withType(JavaCompile) {  
    options.encoding = "UTF-8"  
}  

解决注释乱码问题:
右下角utf-8换成GB2312,选择reload就可以了

5、对于9-patch图的错误:

Error: Process 'command finished with non-zero exit value 42

 使用Android Studio自带的9-patch图编辑器,修改完没有保存,还是会报错。
 使用Eclipse的SDK下的tools中的工具修改之后,再拷贝过来就正常了。

6、对于jpg改成png而被Android Studio识别出来不能通过的,可以设置忽略这项检查,在app的build.gradle中,设置android:

aaptOptions.cruncherEnabled = false;
aaptOptions.useNewCruncher = false;

7、依赖项目引起的错误:

Error:(43, 9) Attribute application@icon value=(@drawable/new_app_icon) from AndroidManifest.xml:43:9 is also present at com.github.erizet.signala:signala-longpolling:0.20:7:18 value=(@drawable/ic_launcher)
Suggestion: add 'tools:replace="android:icon"' to  element at AndroidManifest.xml:40:5 to override
:OpenBook:processDebugManifest FAILED
Error:Execution failed for task ':OpenBook:processDebugManifest'.

Manifest merger failed with multiple errors, see logs

解决方法

Solved it by adding to my manifest tag xmlns:tools="http://schemas.android.com/tools"
Then added tools:replace="android:icon,android:theme" to the application tag.
This tells the merger to use my manifest icon and theme and not of other libraries

8、在使用的依赖项目中,如果它的Manifest中也含有

    
        
     

 有可能导致程序先启动该module的Activity。

9、Android Studio上的app打叉:

android studio default activity not found

解决方法
If you see that error occur after upgrading your IDEA, upgrading Android Studio version, or Generating a new APK, you may need to refresh the IDE's cache.

File -> Invalidate Caches / Restart...

10、Android Studio中的ButterKnife插件无法使用,不显示提示内容:

It seems that jcenter has an invalid ssl.

解决方法

As workaround try to add this to build.gradle

repositories {
    mavenCentral()
    jcenter {
         url "http://jcenter.bintray.com/"
    }
}

11、Android Studio坑爹问题

import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity{
    ……
}

这里找不到support.v7的包,
因为我打开了另一个也引了support.v7包的项目,导致当前项目中无法找到。

你可能感兴趣的:(Eclipse中的项目迁移到Android Studio填坑)