Android gradle编译引用下载的三方aar包保存的本地目录位置:
C:\Users\Administrator\.gradle\caches\modules-2\files-2.1\
如图:
android项目中的模块需要使用本地aar文件,运行正常build出错:Direct local .aar file dependencies are not supported
在Android项目中,直接使用本地.aar文件作为模块依赖是不被支持的。这是因为Android项目的依赖管理一般使用Gradle构建,而Gradle只支持使用Maven、JCenter、Google等远程仓库和本地maven仓库的依赖。
如果您需要使用本地.aar文件作为模块依赖,可以将该文件转换为本地maven仓库格式,然后将其添加到项目中的build.gradle文件中进行引用。操作步骤如下:
1. 将.aar文件拷贝到项目中的某个文件夹下,比如将其拷贝到项目根目录下的libs文件夹中。
2. 在项目根目录下的build.gradle文件中添加以下代码,用于定义本地maven仓库路径:
repositories {
maven {
url uri('libs')
}
}
其中,url uri('libs')指定了本地maven仓库的路径为项目根目录下的libs文件夹。
3. 在需要使用该.aar文件的模块的build.gradle文件中添加以下代码,引用该文件:
dependencies {
implementation 'com.example:samplelibrary:1.0@aar'
}
其中,com.example和samplelibrary是库的GroupId和ArtifactId,1.0是版本号,@aar表示使用的是本地.aar文件。
4. 在终端中进入到项目根目录下,运行以下命令将.aar文件安装到本地maven仓库中:
./gradlew install
5. 运行项目即可使用该本地.aar文件作为模块依赖。
We recently upgraded to Android Gradle Plugin 4.0.0-beta03. We are now seeing this error when building one of our library modules
$ ./gradlew library_module:assemble Execution failed for task ':library_module:bundleDebugAar'. > Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :library_module project caused this error: ______.aar
I can see this was added to AGP a few months ago. But they provide no further info on why.
So.
- What was the problem? Any more info? I can't find a single bug report anywhere.
- How exactly can I fix this? Is this saying that I can't build one .aar that depends on other local .aars? What if this local aar was instead hosted on Maven Central or another remote repo? Why would that make a difference?
-
@spollom@google.com some comment on this?– DavidMay 5, 2020 at 23:51
-
The whole problem is that this would resulted in a kind of fat AAR. Which is not any trivial task, but definitely something Google could do (as they have all the tools for it already working - they are able to merge any number of AARs into the APK), so they probably just do not want to (as the transitive dependencies are more proper way, in most of the cases). There is an existing community solution for this - see github.com/kezong/fat-aar-android - but be warned, it is not mature (e.g. does not support multi-flavour builds, or support for new AGP versions is coming too late, ...).– Jiří KřivánekJun 8, 2022 at 6:25
22 Answers
I recently encountered the same issue, the fix was to remove the library from libs/
and import it using File -> New -> New Module -> Import .JAR/.AAR Package
, then referencing it in the library module build.gradle
file:
dependencies {
implementation project(":imported_aar_module")
}
If you are on a newer Android Studio version (4.0.0+), this option is not available. Instead you have to do it manually.
- Create a new directory and put the following content into the
build.gradle
file withing the new directory:
configurations.maybeCreate("default")
artifacts.add("default", file('[nameOfTheAar].aar'))
- Place the
aar
into this new directoy. Next to thebuild.gradle
file. - Add the new created Gradle project to the
settings.gradle
file:
include(":pathToTheCreatedDirectory")
- Include the project in your library where you want to use the
aar
:
implementation project(":pathToTheCreatedDirectory", configuration = "default")
-
9With this solution we would suddendly need a few more modules. Sad that there are no more infos about this new warning, it's not really logical to me, our project works how it is.– DavidMay 5, 2020 at 13:55
-
9Just a heads up comment - I was looking for a solution where one AAR can contain another AAR. That is not the case with this answer. Second AAR is created successfully but it isn't bundled with the first one. Dec 8, 2020 at 15:16
-
30
-
18When I do this I get
Could not set unknown property 'configuration' for settings 'android' of type org.gradle.initialization.DefaultSettings.
, anyone else run into that? Gradle plugin 4.2.2.– MaxMar 5, 2022 at 16:57 -
8
implementation project(":pathToTheCreatedDirectory", configuration = "default")
causes errorCould not set unknown property 'configuration'...
____________________implementation project(":pathToTheCreatedDirectory")
works. Jun 30, 2022 at 6:58
I also hit this issue when I increase my Android plugin version to 4.0.1, and it turns to error, tried some solutions but none of them are actually doable in our project.
Since we are using product flavours, and different flavours are using different local aar file, we simply can not just using api(name: "xxx", ext: 'aar')
since those aar files are located in different flatDir
.
For now I have to roll back to previous gradle plugin version.
will edit this answer if I figure something out
It is bug in Android Studio 4.0.+.However, there is a solution.
First, project/build.gradle:
allprojects {
repositories {
google()
jcenter()
mavenCentral()
flatDir {dirs "../MoudleA/aars,../MoudleB/aars,../MoudleC/libs".split(",")
}
}
}
Second, Moudle/build.gradle:
// MoudleA/build.gradle
repositories {
flatDir {
dirs 'aars'
}
}
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
//api fileTree(dir: 'aars', include: ['*.aar'])
// aar
new File('MoudleA/aars').traverse(
nameFilter: ~/.*\.aar/
) { file ->
def name = file.getName().replace('.aar', '')
api(name: name, ext: 'aar')
}
}
// MoudleB/build.gradle
repositories {
flatDir {
dirs 'aars'
}
}
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
//fullApi fileTree(dir: 'aars/full', include: ['*.aar'])
//liteApi fileTree(dir: 'aars/lite', include: ['*.aar'])
// aar
new File('MoudleB/aars/full').traverse(
nameFilter: ~/.*\.aar/
) { file ->
def name = file.getName().replace('.aar', '')
fullApi(name: 'full/' + name, ext: 'aar')
}
new File('MoudleB/aars/lite').traverse(
nameFilter: ~/.*\.aar/
) { file ->
def name = file.getName().replace('.aar', '')
liteApi(name: 'lite/' + name, ext: 'aar')
}
}
// MoudleC/build.gradle
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
//api fileTree(dir: 'libs', include: ['*.jar','*.aar'])
api fileTree(dir: 'libs', include: ['*.jar'])
// aar
new File('MoudleC/libs').traverse(
nameFilter: ~/.*\.aar/
) { file ->
def name = file.getName().replace('.aar', '')
api(name: name, ext: 'aar')
}
}
It works for me,You can also try.
When building an Android library that depends on other Android libraries (i.e., aar
files), you will get the following error message if you include the aar files as dependencies in the project:
Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error).
As the above message states, when you build an Android library project, any aar it depends on is not packaged. If you built this way prior to AGP (Android Gradle Plugin) 4, you probably noticed that you had to include the aar dependencies on the project consuming your library.
You can compile your Android library project by specifying that the aar dependencies are compileOnly
. See this for more info on when to use compileOnly
.
So just add the following to your app
build.gradle
file:
compileOnly files('libs/some-library.aar')
Note that if you do this you will have to include the aar dependencies on the application project that consumes your library.
Alternatively, you can create a module that imports your aar
dependency as @Sandi mentioned in the answer above.
Another way is to publish your aar
dependencies to a maven repository and then add them to your library project like this:
implementation 'mylibrarygroup:mylibraryartifact:version-x.y.z@aar'
-
7Not sure how this answer ever helped anyone. Google states: "You can't use the compileOnly configuration with AAR dependencies." in their docs: developer.android.com/studio/build/dependencies Mar 30, 2021 at 8:30
-
1@DarkNeuron that's because the OP's use case is different: you have a library project that compiles to an aar which also depends on other aars. So for this case, compileOnly works with the caveats noted in my answer (i.e., you have to include the aar dependencies that are compile only in the project consuming the library)– LuisMar 30, 2021 at 23:33
-
1What? No no, my use case was exactly the same: Was building a library that used an AAR. I posted the above because it did NOT work. Everything compiled, but the library was missing from the final bundle. Which left me confused until I saw that note by Google. In any case I solved my aar problem by extracting the jar file contained within. Which might not work for everyone. Apr 1, 2021 at 11:17
-
2@Żabojad then you didn't understand the above answer. You have to include the dependencies.– LuisFeb 8, 2022 at 5:01
-
1How to include the aar dependencies on the application project that consumes your library ? how to publish your aar dependencies to a maven repository ? @Luis Sep 22, 2022 at 9:00
There are some changes now, You need to add your AAR or JAR as a dependency
1.) First, Navigate to File > Project Structure [Reference Image 1]
2.) Then go to Dependencies > Declared Dependencies tab, click and select JAR/AAR Dependency in the dropdown [Reference Image 2]
3.)In the Add Jar/Aar Dependency dialog, first enter the path to your .aar or .jar file, then select the configuration to which the dependency applies. If the library should be available to all configurations, select the "implementation" configuration. [Reference Image 3]
4.) Click OK then Apply > OK.
You are good to go.
-
It works! But the file structure is different from the Sandi's answer. Jan 4, 2022 at 6:35
-
2I tried this for a library module and it did not work. This is what the OP is about. I am quite sure this approach works perfectly for an app module.– HongApr 20, 2022 at 14:25
-
I did this, and it worked until I renamed the project directory. Tried to redo it, not working.– John TJul 16, 2022 at 0:41
Getting same error when use this code.
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation fileTree(include: ['*.aar'], dir: 'libs')
Replace your code with following.
Open the top level ‘build.gradle’ file and add.
repositories {
flatDir {
dirs('/src/main/libs')
}
}
Then in your project’s build.gradle add the following.
api(name:'aar_module_name', ext:'aar')
EDIT : if the AAR does not contain android resources or native code, this could help you.
If you want this local resource directly linked to an "app" or "sdk" module (no compileOnly)
=> Use a jar.
- Rename the .aar to .zip
- Extract it
- Use the classes.jar inside
That's it.
-
2jars are not equivalent to an aar, they can't contain native code or other android resources. Jul 18, 2021 at 1:11
-
Of course. But when this is not the case this trick could be useful.– michgauzJul 19, 2021 at 9:21
I had the same issue, in the sense I wanted to encapsulate a library dependency into a module. However this library dependency had a bunch of aars and creating separate module each of them is just clutter, and can't even find that option in the new studio.
To resolve it I published the aar-s into my local maven, before starting the build process.
So my encapsulating module's build.gradle looked like this:
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'maven-publish'
}
//..
parent.allprojects { // for some reason simply repositories didn't work
repositories {
mavenLocal()
}
}
//...
publishing {
publications {
barOne(MavenPublication) {
groupId 'foo-aar-dependency'
artifactId 'bar1'
version '1.0'
artifact("$libsDirName/bar1.aar")
}
barTwo(MavenPublication) {
groupId 'foo-aar-dependency'
artifactId 'bar2'
version '1.0'
artifact("$libsDirName/bar2.aar")
}
barThree(MavenPublication) {
groupId 'foo-aar-dependency'
artifactId 'bar3'
version '1.0'
artifact("$libsDirName/bar3.aar")
}
// and so on...
}
}
// add the publication before the build even starts
// used ./gradlew mymodule:assemble --dry-run to find where to put it
afterEvaluate {
tasks.clean.dependsOn("publishToMavenLocal")
tasks.preBuild.dependsOn("publishToMavenLocal")
}
dependencies {
implementation "foo-aar-dependency:bar1:1.0"
implementation "foo-aar-dependency:bar2:1.0"
implementation "foo-aar-dependency:bar3:1.0"
// and so on
// also I had to make sure to add the aar's transitive dependencies as implementation below
}
Note: When I sync for the first time the dependencies are not found, but as soon as any clean/assemble is called the dependencies are published prior so it runs as it needs.
Note2: most of this can be moved into a separate file to not clutter your build.gradle
Note3: If you actually want to publish your module as a library this solution is not for you.
Note4: This also works on CI if you run clean then your next task.
-
2this is the true answer! Maven is recommended over unsupported AAR dependencies, and I have been looking for a way to use my local AARs/artifacts from mavenLocal. Bravo and thank you @Gergely Hegedus!– JeffAug 11, 2022 at 15:26
-
This solution work perfectly, covering encapsulation if you're planning to publish library. You saved my week !!– Son TieuNov 15, 2022 at 9:30
-
@SonTieu did you publish your library to mavenCentral with local AAR dependencies? Does this solution work for mavenCentral or only mavenLocal? Nov 15, 2022 at 16:52
-
@KuvonchbekYakubov i tried to use my own aar, so this solution worked in my case with mavenLocal. I haven't tried to publish to mavenCentral though.– Son TieuNov 18, 2022 at 2:28
-
@Gergely Hegedus If my aar have dependencies, how would you declare it in this case ? i want something like specifying where my aar's pom is, along with my aar artifact.– Son TieuNov 18, 2022 at 2:30
In my experience, when Gradle Plugin version is 4.2.2+ and Gradle version is 7.1+, as in @Luis's answer 'compileOnly' works.
compileOnly files('libs/your_library_name.aar')
It didn't work when the Gradle versions were lower.
-
13With this it compiles but later on in the app it crash when I try to call this lib– murtOct 18, 2021 at 7:49
-
-
1Yes it compiles indeed, but the aar is then not loaded at runtime and the app crashes.– ŻabojadFeb 7, 2022 at 16:28
-
2Yes, this is only half the answer. @Luis answer add the important addition; "Note that if you do this you will have to include the aar dependencies on the application project that consumes your library." See Simon answer for how to do that.– BenClarkFeb 28, 2022 at 13:10
If you want to bundle a local .aar
within your library and use that library in another project, you could take a look at "fat aars" https://github.com/kezong/fat-aar-android
-
1Be warned: The FAT AAR somehow works. But it is NOT mature enough. It only supports some AGP features. Notably, it does not support multi-flavour builds. Also, it is a community effort, so it is always behind the head (support for new AGPs is coming easily 1 year later). It is a real shame that Google is too lazy to add and maintain the FAT AAR feature themselves. They already have all the required functionality (they are able to merge any number of AARs when producing the APK). Jun 8, 2022 at 6:15
Much lazier way to do this in build.gradle.kts files is to use a fileTree
combined with flatDir
repository.
repositories {
flatDir {
dir("$rootDir/libraries")
}
}
dependencies {
fileTree("$rootDir/libraries").forEach { file ->
implementation(group = "", name = file.name.removeSuffix(".aar"), ext = "aar")
}
}
This way when you add or remove deps to the folder they are automatically configured
In my case, I realised that I have created libs folder at wrong place then recreated folder in main
folder and implementation fileTree(include: ['*.aar'], dir: 'libs')
worked.
I want to call out @StefMa's comment on this question which was incredible simple and solved this issue for me, but it's buried among many other comments on this thread and is easily missed.
The 'correct' answer on this thread no longer works because it's not possible to import AARs in Android Studio anymore as referred to in that answer. But, the solution referred to in StefMa's comment linking to this GitHub post does, and it works perfectly.
Long story short - put your AAR into a separate module.
There's no need to muck around with creating lib directories, just follow these directions -
-
Create a new directory in your project's root directory. The image below shows two of them -
spotify-app-remote
andspotify-auth
, but one is sufficient. Within that, put your AAR in, and create a newbuild.gradle
file. -
Within the
build.gradle
file, add the following, replacing the aar filename with the name of your AAR file -configurations.maybeCreate("default") artifacts.add("default", file('spotify-app-remote-release-0.7.1.aar'))
-
Add this to your
settings.gradle
file, substituting the name of the directory you createdinclude ':spotify-app-remote'
-
Include your new module in the module you wish to use the AAR. eg, if you want to use it within your
app
module, open app'sbuild.gradle
and addapi project(':spotify-app-remote')
within your
dependencies { }
block, obviously again substituting spotify-app-remote with whatever the name of your module is.
-
3
-
9This should be the accepted answer in 2021 and onward. This is really dumb to have to do this manually. So something tells me the developers of Android Studio aren't so stupid as to leave it this way , so probably in the next release of Android Studio, we'll all be back here trying to figure out yet another way of doing this. Feb 8, 2022 at 20:58
-
2Is it possible to add multiple AARs to a to a single
library module
by adding multipleartifacts.add
clauses? Feb 17, 2022 at 8:58 -
3would it be possible to create example repo with this? I have an issue where gradle reports that "spotify" project cannot be found (I used my own name in my code) Jul 7, 2022 at 8:33
-
2I get "Internal error: Artifact type null not expected, only jar or aar are handled." when trying to use the module as a dependency for any other modules :/– BrandonDec 6, 2022 at 7:30
for me works this solution: put into dependences in build.gradle:app file this string:
api fileTree(dir: 'libs', include: ['*.aar'])
Adapt aar dependency to maven repo standards and depend on it.
Lets connect the dependency in build.gradle
repositories {
maven { url "$project.projectDir/libs" }
}
dependencies {
api "my-library-group:my-library-module:my-library-version"
}
Replace you libs/myLibrary.arr
file with next files:
libs/my-library-group/my-library-module/my-library-version/my-library-module-my-library-version.aar
libs/my-library-group/my-library-module/my-library-version/my-library-module-my-library-version.pom
libs/my-library-group/my-library-module/maven-metadata-local.xml
Where my-library-module-my-library-version.aar
is the original aar file
Content of my-library-module-my-library-version.pom
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>my-library-group</groupId>
<artifactId>my-library-module</artifactId>
<version>my-library-version</version>
<packaging>aar</packaging>
</project>
Content of maven-metadata-local.xml
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>my-library-group</groupId>
<artifactId>my-library-module</artifactId>
<versioning>
<latest>my-library-version</latest>
<release>my-library-version</release>
<versions>
<version>my-library-version</version>
</versions>
<lastUpdated>20211130111015</lastUpdated>
</versioning>
</metadata>
Feel free to replace my-library-group
, my-library-module
, my-library-version
with any value you like
-
I have tried but getting error. Can u please post your full build.gradle files or post the github link for convenience. @Link182 Aug 15, 2022 at 14:20
For those who prefer to use as a regular dependency (or an item on your Gradle's version catalog):
- Create a folder eg.
spotifyAppRemote
at the same level ofapp
folder - Add the desired
.aar
file at the root ofspotifyAppRemote
folder - Create a
settings.gradle.kts
file at the root ofspotifyAppRemote
folder. This file will be empty, it just needs to be there for the composite builds. See: docs - Create a
build.gradle.kts
file at the root ofspotifyAppRemote
folder:
plugins {
base //allows IDE clean to trigger clean on this module too
}
configurations.maybeCreate("default")
artifacts.add("default", file("spotify-app-remote-release-0.7.2.aar"))
//Change group to whatever you want. Here I'm using the package from the aar that I'm importing from
group = "com.spotify.android"
version = "0.7.2"
- Next add Gradle files to this folder to allow this module to build itself. You can do it manually or add the following snippet at the root of
settings.gradle.kts
(!! the project root, not the empty one created above)
/* Optional - automatically sync gradle files for included build */
rootDir.run {
listOf(
"gradle.properties",
"gradlew.bat",
"gradlew",
"gradle/wrapper/gradle-wrapper.jar",
"gradle/wrapper/gradle-wrapper.properties"
).map { path ->
resolve(path)
.copyTo(
target = rootDir.resolve("spotifyAppRemote").resolve(path),
overwrite = true
)
}
}
- Now you can go ahead and add this folder as a module at the
settings.gradle.kts
on your project root. The same where may add the snippet above:
rootProject.name = "Your project name"
include(":app")
includeBuild("spotifyAppRemote")
- Sync and build your project.
- Now your included build will be available for your as a regular dependency with the defined group and version. To use this dependency:
dependencies {
// group:moduleName:version
implementation("com.spotify.android:spotifyAppRemote:0.7.2")
}
Thanks other members for the solution.
Source code on github: https://github.com/rsicarelli/SpotifySdkCompositeBuild
-
-
2This solution works properly (the library builds and the module classes are available) but if I export the library as .aar into another Android project, the module code is missing. Inspecting the library .aar file, it does not embed the dependency module. Oct 21, 2022 at 11:12
-
-
1@Lukᚊálek I've opened a new question, but noone has given any answer yet. It's incredible that Google does not provide any clear information about that. Oct 24, 2022 at 8:47
-
1You literally saved my day! Very precise, detailed explanation on your Github page. Thank you ! Jul 11 at 15:49
Patch the problematic 3rd party dependency's build.gradle file. Under their dependencies { } section, they had a line like this:
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar']) //Load all aars and jars from libs folder
My patch changes that line to:
implementation(name: 'the-name-of-the-aar', ext: 'aar')
In my project's build.gradle, under allprojects { repositories { }, added:
flatDir { dirs "$rootDir/../node_modules/the-third-party-dependency/android/src/main/libs" }
Where the AAR file lives
It was tested with reactnative >= 0.69.x
-
1
-
I faced a similar problem:
Task: add .aar
SDK inside another SDK
Solution:
-
We have to create new Android Library Module inside our library (right click on our library name -> module -> Android library )
-
Delete all files inside it
-
Insert our
.arr
inside this module -
Create
build.gradle
file inside module and put there:configurations.maybeCreate("default") artifacts.add("default", file('your_arr_name.aar'))
-
Add to your library
build.gradle
inside dependencies block next:implementation project(':your_library:your_arr_module')
-
Now rebuild project and everything should work fine
-
It's the only answer that worked for me. Additionally, I had to manually move the created module folder inside my library's folder. I also noticed that root-level
settings.gradle
was appended withinclude ':your_library:your_arr_module'
, which is important to include if you're linking a React Native library. [I had an issue withreact-native-spotify-remote
library which failed on the release Gradle build, so I had to fork it & apply this fix]– DanielJan 25 at 14:53 -
I follow this step, and solve my problem.but face a new problem that I can't get style, string, drawable and other resources in my java code like R.style.xxx R.string.xxx– DavidMar 24 at 0:50
Good news for everyone. It seems that we can finally include AARs without subprojects again. I was able to accomplish it using the implementation files
directive as follows in the dependencies { }
block:
implementation files('ssi.aar')
-
1
-
-
@MoustafaEL-Saghier you can put the file anywhere. it doesn't have to be the libs folder.– so001Mar 15 at 21:11
-
When I don't use
libs/
beforessi.aar
, it doesn't find the aar:Null extracted folder for artifact: ResolvedArtifact(componentIdentifier=ssi.aar, variant=local file, variantName=null, artifactFile=.../moduleName/ssi.aar, isTestFixturesArtifact=false, extractedFolder=null, publishedLintJar=null, dependencyType=ANDROID, isWrappedModule=false, buildMapping={__current_build__=/projectName})
. And when I use, I still get the same error as the question– Dr.jackyApr 6 at 13:22
My use case was for creating a Flutter Plugin but the solution was still the same as Link182's. I did find an implementation that I used as an example on Github
However, I had to use explicit version (X.X.X
) rather than +
to get it to work after creating maven directories, .pom, and manifest files: api(group: 'com.example.group', name:'exampleArtifact', version: '1.0.0')
Rather than creating a new module for the .aar
. A much simpler approach is to have the app module add the .aar
file as a dependency. The library module could just have a compileOnly
dependency on the .aar
file.
I usually set it up in the following way,
In the root directory, I have a folder global-libs
. Copy the .aar
library file here.
app-module
-
implementation(files("../global-libs/some-lib.aar"))
library-module
-
compileOnly(files("../global-libs/some-lib.aar"))
This way the .aar
is bundled in the final apk, and the build also succeeds without any warning.
方法/步骤
-
首先,用Android Studio创建一个Android项目,然后找到我们需要引用的本地arr文件
-
将本地arr文件Copy到我们项目的libs文件夹下,没错就是和jar放在同一个文件夹下,这里需要注意的是:是放在主项目的libs文件夹下,别放错了
-
Copy完以后,打开我们主项目下的build.gradle构建文件
-
然后再构建文件中输入
repositories{ flatDir { dirs 'libs' }}
这是一个本地的“仓库”不要写错了
-
然后接着在构建文件的dependencies大括号中,输入compile(name:'arcgis-android-v10.2.7', ext:'aar'),“arcgis-android-v10.2.7”是arr文件的文件名,“arr”则是文件的扩展名,别写错了
-
以上操作完成后,点击菜单栏的重新构建按钮,对项目进行重新构建,然后稍等一下
-
如果没有发生错误的话,我们打开依次主项目的build--->intermediates--->exploded-aar,就会看到我们刚才引用的arr文件,到此arr文件就引用成功了
END
注意事项
-
Android Studio引用arr文件和libary文件相比于Eclipse来说,个人觉的还是比较麻烦的,所以还请各位学习一下,重在积累么
-
如果喜欢小编的经验,请投上您宝贵的一票
如何在安卓(Android studio)项目中导入模块、jar包、和aar包
wstcl
已于 2022-03-02 15:09:15 修改
3362
收藏 2
文章标签: android 安卓
版权
安卓(Android studio)编程中,我们常需要引用”别人写的功能“,以扩展app的功能,”别人写的功能“主要有模块、jar包、和aar包三种方式。
下面说一下调用(引用)三者的方法。
模块:
菜单file->new->import moudle->选择需要的模块(图1),。然后在在build.gradle(app)中添加依赖implementation project(’:模块名’)。完成。
jar包:
1.左侧project标签,切换到project。(图2、图3)
2.将jar包复制根节点\app\libs(没有libs手工新建)。
3.在jar包上右键Add as library。
完成。
aar包
1、2步同jar包。
3.打开build.gradle(app),在build.gradle(app)的android节点添加
repositories {
flatDir{
dirs(‘libs’)
}
}
4.在dependencies节点添加 api(name: ‘aar名称’, ext: ‘aar’)。
上述三者引用后不要忘记重新生成一下项目。
————————————————
南来地,北往的,上班的,下岗的,走过路过不要错过!
======================个性签名=====================
之前认为Apple 的iOS 设计的要比 Android 稳定,我错了吗?
下载的许多客户端程序/游戏程序,经常会Crash,是程序写的不好(内存泄漏?刚启动也会吗?)还是iOS本身的不稳定!!!
如果在Android手机中可以简单联接到ddms,就可以查看系统log,很容易看到程序为什么出错,在iPhone中如何得知呢?试试Organizer吧,分析一下Device logs,也许有用.