Android Studio版本
Eclipse项目工程:一个主工程,一个Emojicon依赖库。
有两种方式导入Eclipse工程:
1、兼容Eclipse
2、全新的Android Gradle Project
Google推荐用全新的方式,所以此处不介绍兼容模式导入。
请先关闭Android Studio当前的Project,否则你看不到Import Project。
选择“Import project(Eclipse ADT, Gradle, etc.)”,定位到你所需要导入的工程的主目录。由于主目录和Emojicon有依赖关系,Android Studio会自动关联进来。然后指定一个保存的目录,点击Next。
默认情况下,下面的选项会打上勾(如果没有勾上,手动勾上),直接Finish就行了。
一段时间转换后,你将看到以下的结构
我把主工程的名称隐藏了,此时可以看到,Emojicon确实导进来了。不过Emojicon下的java目录是我后面加进来的,默认导入时这个文件夹不存在,为什么?往下看。
Android Studio导入完毕后,会默认在窗口中打开这个import-summary.txt文件,里面记录了导入的一些注意事项。这个文件有几个需要注意的节点,如下:
Manifest Merging
Ignored Files
Replaced Jars with Dependencies
Manifest Merging中的文字如下,也就是描述你的清单文件,基本上不用管。
Your project uses libraries that provide manifests, and your Eclipse
project did not explicitly turn on manifest merging. In Android Gradle
projects, manifests are always merged (meaning that contents from your
libraries' manifests will be merged into the app manifest. If you had
manually copied contents from library manifests into your app manifest
you may need to remove these for the app to build correctly.
Ignored Files,这个部分很重要。它表示Android Studio在导入项目的时候把这些文件忽略了,如果需要的话,你得手动拷贝进来。因为主工程依赖Emojicon,所以把这个文件拷贝到相应的位置即可。
The following files were *not* copied into the new Gradle project; you should evaluate whether these are still needed in your project and if so manually move them: From Emojicon: * .gitignore * java\ * java\com\ * java\com\rockerhieu\ * java\com\rockerhieu\emojicon\ * java\com\rockerhieu\emojicon\EmojiAdapter.java * java\com\rockerhieu\emojicon\EmojiconEditText.java * java\com\rockerhieu\emojicon\EmojiconGridFragment.java * java\com\rockerhieu\emojicon\EmojiconHandler.java * java\com\rockerhieu\emojicon\EmojiconSpan.java * java\com\rockerhieu\emojicon\EmojiconTextView.java * java\com\rockerhieu\emojicon\EmojiconsFragment.java * java\com\rockerhieu\emojicon\emoji\ * java\com\rockerhieu\emojicon\emoji\Emojicon.java * java\com\rockerhieu\emojicon\emoji\Nature.java * java\com\rockerhieu\emojicon\emoji\Objects.java * java\com\rockerhieu\emojicon\emoji\People.java * java\com\rockerhieu\emojicon\emoji\Places.java * java\com\rockerhieu\emojicon\emoji\Symbols.java
Replaced Jars with Dependencies,提示你原来的jar包在Android Studio项目中会以何种方式存在。
The importer recognized the following .jar files as third party
libraries and replaced them with Gradle dependencies instead. This has
the advantage that more explicit version information is known, and the
libraries can be updated automatically. However, it is possible that
the .jar file in your project was of an older version than the
dependency we picked, which could render the project not compileable.
You can disable the jar replacement in the import wizard and try again:
android-support-v4.jar => com.android.support:support-v4:22.2.1
以前的libs文件夹哪里去了呢?
右击你的Module,Open Module Settings,显示如下:
其实Android Studio可以添加在线的库和jar,看到Maven Central字样了吧?相应的Jar会按需下载。
至此,项目可以build了。想运行成功,还没那么容易。
Error:duplicate files during packaging of APK ........
说是duplicate files copied in APK META-INF/NOTICE.txt
duplicate files copied in APK META-INF/LICENSE.txt
解决办法:在你的module下的build.gradle中的android节点中添加packagingOptions
android { …… packagingOptions{ exclude 'META-INF/NOTICE.txt' exclude 'META-INF/LICENSE.txt' } }
还有一个错误提示: Manifest merger failed with multiple errors, see logs
Suggestion: add ‘tools:replace=”android:icon”‘ to <application> element at AndroidManifest.xml:24:5 to override
原因:Android Studio默认使用Manifest Merger Tool,如果Library项目也定义了与主项目相同的属性(如默认生成的android:icon, android:theme),则会合并失败。
解决1:在AndroidManifest.xml节点manifest中引入
xmlns:tools="http://schemas.android.com/tools"
然后在application节点添加
tools:replace="android:icon"
或需要屏蔽theme,中间用逗号隔开。
tools:replace=”android:icon, android:theme”
解决2:在build.gradle根标签上加上useOldManifestMerger true,不过在Android Studio 2.0中提示找不到这个useOldManifestMerger ,不知是改进过了还是用了其它的字段(此法有问题,有谁知道为什么么?)。
android {
useOldManifestMerger true
}
请参考官方介绍: Manifest Merger
顺利的话,基本上就是这两个问题,然后就可以run了。