Steps and precautions for transferring eclipse project to Android studio project

Gradle Foundation

To turn eclipse into an Android studio project, gradle syntax is a required course. If you introduce an article here, you won't write the foundation, gradle foundation

introduction

At present, it is the general trend to develop Android projects with Android studio, and even Google has announced that it no longer supports eclipse. Therefore, it is necessary to transfer some old eclipse projects to Android studio projects. There are two types of project transformation: one is the compatible mode, that is, the project structure that can be used by both eclipse and Android studio; One is the directory structure of Android studio. Here, first record the conversion method of compatibility mode.

1、 Exporting gradle files from eclipse

First, make sure that eclipse contains the gradle plug-in. Select File - > export - > generate gradle build files from the menu,

Next, check the projects to be converted (if there are dependent projects, check the dependent projects too). Before finishing, it is best to check force overriding of existing files to ensure that the files existing in the project due to previous similar operations are overwritten.

2、 Modify gradle file parameters

Now, there are several gradle related files in the project. Modify two places to the latest version:

1.build.gradle。

find

Change to

2.gradle/wrapper/gradle-wrapper.properties。

find

Change to

3、 Import Android studio

Select import project (eclipse, ADT, gradle, etc.) on the welcome interface of Android studio

Select the project and wait for the compilation to complete. At this time, the compilation will not succeed immediately. You need to be patient and modify the errors according to the compilation error information. Common errors include: JNI library location, low build tool version, image check error, manifest conflict, jar package conflict, etc.

4、 Common compilation errors and Solutions

1. JNI library location. Add in build.gradle:

2. The build tool version is low. Generally, Android studio will be prompted to improve the build tool version.

3. Check the picture and report an error. Put the. 9 pictures in the dawable folder instead of the mipmap folder; Add in build.gradle:

4. Manifest conflict. Delete duplicate uses permission permissions; Ignore manifest resource value conflicts:

Add the following to the manifest root tag:

Then, under the application tab, add:

Or add it directly in gradle:

5. Jar package conflict. Delete the jar package in the library project that conflicts with the main project.

5、 AAR package for Library Project

If there is a dependent project in the project (i.e. library project, which is called module project in Android studio), it is best to make it into AAR package to improve the compilation speed during daily debugging. Because every time Android studio compiles, it will compile all the projects under the project, which will waste some unnecessary time. Therefore, if it is not a special case, it is best to use the module project as an AAR package. How to generate this AAR?

First, when we finish the previous operation, the program runs normally.

Find the AAR package generated by compilation under \ build \ outputs \ AAR \ of the module project, and copy the AAR package to \ LIBS \ of the main project.

Remove the include of the original project from the settings.gradle file in the root directory:

Change the project dependency of build.gradle file in the main project to AAR package dependency:

Click sync now in the upper right corner and wait for gradle to complete. Then it's OK. Isn't it very simple!

Considerations for novice Android studio to import eclipse project

1. Apply plugin: 'com. Android. Library' in the build.gradle that introduces the moudle indicates that the current moudle is a library instead of the apply plugin: 'com. Android. Application'

2. Use gradle everywhere in eclipse. If there is an application node in the manifest file in library, please delete it, otherwise an error will be reported, because gradle will find two application nodes during compilation.

3. Because Android studio has strict requirements for image format, it will generally report image format error AAPT err (facade for 1059284777): libpng error: not a PNG file when switching from eclipse. Please modify it according to the following instructions:

Add the following to the Android item under build.gradle in app:

4. If there are the same jars in the main project and libary, there will be no error in eclipse, while class duplicate errors will be reported in Android studio. Then we can delete the duplicate jars in the main project and libary.

5. The Android studio project transferred from eclipse will not add the so path by default. It can be compiled successfully or installed successfully, but the error is reported when it is started. It can be seen that the so error is reported, and then the VM hangs up, indicating that the so path is not found. The following code can be configured in build.gradle of the main project to indicate the path of so library. Under LIBS, it can also be specified as other paths.

6. This method is recommended for introducing local jars. You do not need to add every jar you add.

7. After compiling OK, run and report an error: @ r_ 419_ 1750@ not find XXXX in APK; Aborting. Please run again according to the following settings.

File - Settings - build, execution, deployment - instant run, remove the hook on the side of enable instant run

summary

The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>