I think there are many times when you want to add an external library to your Android project. Among the various ways to add libraries, there is only "Import Project / Module" to customize the library source. However, this method had many parts that had to be rewritten, and it was a lot of troublesome work, so I wrote an article instead of a memo.
You probably have a Maven external library that you want to add. First, let's make it possible to manage the Maven library with gradle.
cd [Folder containing the library you want to add]
gradle init --type pom
Android Studio cannot read pom.xml which exists like build.gradle in Maven. Therefore, the above command converts pom.xml to build.gradle.
Now that it's sunny and can be loaded in Android Studio, select the project you want to add the library to and select [File]-> [New]-> [Import Project].
Then select the library you converted earlier. It's finally the turning point here (laughs)
You'll probably get a Gradle Sync error here like this: -I don't have ~ / AndroidManifest.xml? ――The description of ~ / build.gradle is not enough! With a feeling
If you get angry, you have to fix it, so Do as the error says.
AndroidManifest.xml It seems that it is useless without PackageName, so create a new AndroidManifest.xml file described as follows.
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.○○○.△△△"> //Write ○ and △ with reference to Maven(suitable)
<application />
</manifest>
build.gradle
The previous command gradle init --type pom
only ported dependencies, so you have to write the rest yourself.
The following is a sample, but please adjust to your environment as appropriate.
apply plugin: "com.android.library"
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
}
description = 'Library name'
dependencies {
...
}
This is the end of preparation. After that, right-click the project you want to add and select [Configure Project Subset]. I think that the library you imported earlier has not been checked yet, so let's check it.
How about that? The rest is complete if you do a Rebuild Project.
Make a pom.xml project into an Android Library and let the IDE read it
Recommended Posts