Problems and solutions caused by android studio importing third-party libraries

Today I want to use slidingmenu on android studio, and then there are layers of difficulties, almost crashing, but finally solved.

First let's talk about how to import:

1. Import library with import eclipse project

2.File-Project Structure-select app-Dependencies-plus sign on the right-select the third (Module dependency)-associate slidingmenu with app

3. View build_gradle of slidingmenu

dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
}

This part of the code may report an error, just change it to the corresponding value according to the prompt


Even if this is ok, it may be bad and the same error as me occurs.

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_17\bin\java.exe'' finished with non-zero exit value 2


When I saw the path of jdk, I thought it was a problem with the jdk version. I also installed jdk1.7 on purpose, but found it to be useless. After searching, I got the solution:

Add the last sentence to build.gradle under app

defaultConfig {
...
...
    multiDexEnabled true
}

I don't know why, but it solved

Then came this problem again:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/app/ShareCompat$ShareCompatImplJB.class


The multi-party search was fruitless. It bothered me for a long time and almost collapsed. I would like to share the final solution with you.


This should be because the support-v4 support library in the slidingmenu, and the app itself also has this, repeat. So solve it like this:

1..File——Project Structure——Select slidingmenu——Dependencies——The minus sign on the right, so that the support-v4 in the lib directory is gone, and countless red bars appear, and an error is reported

2. Next, associate it with the support-v4 of the app:

.File - Project Structure - select app - Dependencies - plus sign on the right - select the first one (Library dependency), support-v4 will appear, select ok

3. In the same way, the app is also associated with support-v4, and you're done.


The error generated by importing the jar package:

Error:(47, 31) Error: Unable to access HttpRequestBase
Class file for org.apache.http.client.methods.HttpRequestBase not found

Solution:

Add under build_gradle of app

android {
    useLibrary 'org.apache.http.legacy'
}


Android Studio uses a moudle as a class library:

1.import moudle and handle the corresponding errors

2. Set the module to android library, modify the build.gradle under the corresponding module, and modify the value after apply plugin to:

  apply plugin: 'com.android.library'

3. Other moudle set it as a dependency

4. Delete the application tag in the AndroidManifest file in the imported moudle


An error occurred

Error:(2, 1) A problem occurred evaluating project ':library'.
> Plugin with id 'com.github.dcendents.android-maven' not found.


Add in build.gradle under Project

dependencies {
	.........
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
// NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}        

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325413069&siteId=291194637