android studio与eclipse之间项目切换

一、android studio导入eclipse
手工改!!
1.在eclipse 上新建一个空的项目;
2.点击android studio 中的android 视图,
        a.替换as 中的AndroidManifest.xml -> eclipse 中的AndroidManifest.xml;
        b.替换as 中java 目录下源文件 -> eclipse 中的src 目录下的源文件;
        c.替换as 中res 目录下资源文件 -> eclipse 中的res 目录下;
        d.copy as中jniLibs 中的目录 -> eclipse 中的libs 目录下;
        e.copy as中assets 中的目录 -> eclipse 中的assets 目录下;
3.alt + enter, 选择sdk api 版本;
4.eclipse 右键 -> android tools -> fix ,eclipse -> project -> clean project即可

二、eclipse导入android studio

Android Studio版本

Eclipse项目工程:一个主工程,一个Emojicon依赖库。

有两种方式导入Eclipse工程:

1、兼容Eclipse

2、全新的Android Gradle Project

Google推荐用全新的方式,所以此处不介绍兼容模式导入。

请先关闭Android Studio当前的Project,否则你看不到Import Project。

选择“Import project(Eclipse ADT, Gradle, etc.)”,定位到你所需要导入的工程的主目录。由于主目录和Emojicon有依赖关系(Eclipse中需先将两个工程设置关联,即设置加载好依赖库后关闭eclipse),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 
}

工程的编译版本需改为一致,清单文件中权限和文件声明不能重复,应用的图片标签(重复则配置

tools:replace="android:icon, android:label")

,例如我工程的清单文件如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.peihp.happy"
    android:installLocation="preferExternal"
    xmlns:tools="http://schemas.android.com/tools"
     >
    <!--android:sharedUserId="android.uid.system"-->
   <!-- <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="24" />-->

    
    <!-- 在内置SDCard中创建与删除文件权限 -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!-- 在外置SDCard中读写文件权限 -->
    <uses-permission android:name="android.permission.READ_MEDIA_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
    <!-- 往SDCard写入数据权限 -->
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    <!-- 清除缓存 -->
    <uses-permission android:name="android.permission.DELETE_CACHE_FILES" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />
    <!-- 保持屏幕唤醒不锁屏 -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.DEVICE_POWER" />
       …………
   
    <application
        android:name="com.uuzuche.lib_zxing.MyApplication"
        android:allowClearUserData="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/sec_reader"
        tools:replace="android:icon, android:label"
        android:largeHeap="true" >
        …………
    </application>

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true" />

</manifest>

链接库的清单文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.peihp.facelivedetectionsilentlib"
     >

    <!--<uses-sdk android:minSdkVersion="11" />-->

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.kinsec.facelivedetectionsilentlib.FaceLiveDetectionSilentActivity"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar" />
        <activity
            android:name="com.kinsec.facelivedetectionsilentlib.FaceLiveDetectionActivity"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar" />
    </application>

</manifest>

local.properties文件:

#Fri Nov 30 15:37:00 CST 2018
sdk.dir=E\:\\php\\androidTool\\sdk24.4_as\\sdk24.4

keystore.path=E\:/php/androidTool/packSign/peihp.keystore
keystore.password=peihp66
keystore.alias=peihp8888
keystore.alias_password=peihp66

工程build.gradle文件:

apply plugin: 'com.android.application'

def keystoreFilepath = ''
def keystorePSW = ''
def keystoreAlias = ''
def keystoreAliasPSW = ''
// default keystore file, PLZ config file path in local.properties
def keyfile = file('s.keystore.temp')

Properties properties = new Properties()
// local.properties file in the root director
properties.load(project.rootProject.file('local.properties').newDataInputStream())
keystoreFilepath = properties.getProperty("keystore.path")
if (keystoreFilepath) {
    keystorePSW = properties.getProperty("keystore.password")
    keystoreAlias = properties.getProperty("keystore.alias")
    keystoreAliasPSW = properties.getProperty("keystore.alias_password")
    keyfile = file(keystoreFilepath)
}


android {
    signingConfigs {
        config {
            keyAlias keystoreAlias
            keyPassword keystoreAliasPSW
            storeFile keyfile
            storePassword keystorePSW
        }
    }

    compileSdkVersion 27
    buildToolsVersion "28.0.3"
    defaultConfig {
        applicationId "com.peihp.happy"
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 21
        versionName "1.2.2"
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable false
            signingConfig signingConfigs.config
        }
        debug {
            signingConfig signingConfigs.config
        }
    }
    compileOptions {
        encoding "utf-8"
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

dependencies {
    implementation project(':faceLiveDetectionSilentLib')
    implementation 'com.android.support:support-v4:27.1.1'
    implementation files('libs/commons-codec-1.3.jar')
    implementation files('libs/commons-collections-3.2.jar')
    implementation files('libs/commons-httpclient-3.1.jar')
    implementation files('libs/commons-logging-1.1.jar')
    implementation files('libs/commons-pool-1.2.jar')
    implementation files('libs/httpclient-4.3.6.jar')
    implementation files('libs/httpcore-4.3.2.jar')
    implementation files('libs/httpmime-4.3.5.jar')
    implementation files('libs/iTextpdf.jar')
    implementation files('libs/jedis-2.1.0.jar')
    implementation files('libs/ksoap2-android-assembly-3.6.0-jar-with-dependencies.jar')
    implementation files('libs/ldap.jar')
    implementation files('libs/libammsdk.jar')
    implementation files('libs/MKeySDK.jar')
    implementation files('libs/pdf.jar')
    implementation files('libs/plkbluetoothlesdk.jar')
    implementation files('libs/xUtils-2.6.14.jar')
    implementation files('libs/zxing.jar')
}

链接库的build.gradle文件:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 27
    buildToolsVersion "28.0.3"
    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 27
        versionCode = "1"
        versionName = "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

dependencies {
    implementation 'com.android.support:support-v4:27.1.1'
    implementation files('libs/liveness-silent-offline-release.jar')
}

猜你喜欢

转载自blog.csdn.net/P876643136/article/details/84786812