I want to build .AAR with dependencies inside. I was looking for a lot but nothing works. Topics are so old. I realized that resultant .AAR should have classes.jar inside and there are directories with .class files. But I don't know how to automatize this process in gradle.
Android tooling doesn't support it. There's an issue open requesting Google to implement it (feel free to star it to show your support and to help Google to prioritize it).
In the meantime, there are two plugins to try to fix or workaround this lack of support, with limited support of different functionalities:
https://github.com/adwiv/android-fat-aar Old, no longer supported.
https://github.com/Mobbeel/fataar-gradle-plugin Still active, but lagging behind AGP versions (currently working on supporting 3.2 and 3.3... while we're already at 3.4 stable)
So, as you can see the future doesn't look bright.
See also this article for more information.
We manage to do this using this Mobbeel fat AAR Gradle plugin:
https://github.com/Mobbeel/fataar-gradle-plugin
buildscript {
repositories {
//...
maven {
url 'https://plugins.gradle.org/m2/'
}
}
}
//...
dependencies {
classpath 'gradle.plugin.com.mobbeel.plugin:mobbeel-fataar:1.2.0'
}
Mark dependencies with api instead of implementation
apply plugin: 'com.mobbeel.plugin'
dependencies {
api 'org.greenrobot:eventbus:3.0.0'
//...
}
fatAARConfig {
includeAllInnerDependencies false
}
This article was helpful: http://wittchen.io/2018/10/02/creating-fat-aar/
Related
My Android application has duplicated log4j2plugins.dat in dependencies, which caused an error when building:
2 files found with path 'META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat'.
Adding a packagingOptions block may help, please refer to https://developer.android.com/reference/tools/gradle-api/7.3/com/android/build/api/dsl/ResourcesPackagingOptions
for more information
The duplicated resources log4j2plugins.dat are important, so I can't just pick one and ignore the rest.
After google around, I found a plug-in shadowjar that maybe help. According to the official documentation, I added the following directives to build.gradle:
buildscript {
repositories {
mavenLocal()
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
google()
gradlePluginPortal()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0'
}
}
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'java'
}
shadowJar {
transform(com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer)
}
But it doesn't work. the same error, nothing merged.
I don't know much about gradle. (I'm familiar with maven.)
Now the questions:
Some simple merge methods can be performed with packagingOptions, such as pickFirst and merge (just concatenize text lines). Can I customize a new merge method to use in packagingOptions? (for example, merging xml, merging plugins.dat, etc.)
The functions of plugin shadowjar seems to overlap with the functions packagingOptions provides, what is their relationship? What if both are specified? any conflict or sequenced processing by order?
In my android application, how to configure and use the shadowjar plugin to merge log4j2plugins.dat? Though there is official documentation, but It's not work in my case, and I'm not sure if the plugin is useful for general purpose or for android apps.
Thanks!
I followed the getting started guide here, I don't want to migrate to androidx at this time so I did:
Made sure I have the correct repositories
Added com.android.support:design:28.0.0-rc01 to my dependencies, since the Getting Started tutorial states this is the only thing needed if I don't want to migrate to androidx.
Made sure compileSdkVersion was 28
Switched to Theme.MaterialComponents.Light.NoActionBar
Downloaded Android P SDK and sources (but not any of the rest that's not on the image):
Made sure I am using AppCompactAtivity
Rebuilt the project
And I still get the error:
The following classes could not be found:
- com.google.android.material.button.MaterialButton
What am I missing?
You should not use com.google.android.material package instead use com.android.support.
In your case android.support.design.button.MaterialButton
I had that problem with Android Studio 3.2 release candidates, both using com.android.support and using com.google.android.material.
I upgraded to the 3.3 canary and that specific problem went away although I now have other (unrelated?) problems (runtime failures to inflate, etc).
I can't find any documentation stating required Android Studio versions for layout editor to work.
Make sure that the repositories section includes Google’s Maven repository google(). For example:
allprojects {
repositories {
google()
allprojects {
repositories {
google()
jcenter()
}
}
Add the library to the dependencies section:
implementation 'com.google.android.material:material:1.0.0'
dependencies {
// ...
implementation 'com.google.android.material:material:1.0.0'
// ...
}
In recent days I'm getting failed to resolve github libraries for so many popular libraries. I know it generally happens when the library is suspended or not available. But i tried it for so many libraries. And getting same result. But doesn't mean every libraries don't work. Some works.
For example..
I tried it for PhotoView..
compile 'com.github.chrisbanes:PhotoView:2.0.0'
In the release page the latest version was 2.0.0
I get same thing for so many other libraries. I think last week I updated the gradle. So is that why I'm getting this problem for some libraries..
Or what can be the problem..
I'm also using all maven urls for all libraries as mentioned in the docs file..
Make sure you added this root build.gradle file (Not your module build.gradle file):
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
FYI
New version has been released, You can try with
compile 'com.github.chrisbanes:PhotoView:2.1.3'
After that, Clean-Rebuild-Run.
I am building android library project, which has a dependency on another internal library project.
I am wondering if there is a way to package a single AAR library, which already contains internal library inside it. I would like to share only 1 AAR library package to my application developers.
This is how my build.gradle files look currently, but currently they produce separate AAR files and both needs to be included in Application's build.gradle. As application is being built by another company, we need to share the final AAR file with them and not the complete library projects.
----- internalLib -------->>>>>>>>>>
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion '18.1.1'
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
----- externalLib --------
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion '18.1.1'
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile project(':internalLib')
}
There is no mechanism to combine library. It's a bit complicated as you probably want to control which dependencies get merged (for instance you probably don't want to include support-v4 in there). Also you'd need to merge the resources and Android manifest.
At this time there's no way to easily hack something, unless you are sure the resources have no conflicts between the two res folders (for instance you could have strings_a.xml in one lib and strings_b.xml in the other lib). This way you can just "merge" the two res folders by copying them both into the same location (as opposed to do a merge at the android res level).
For the Manifest it'd be more complicated, but doable with some custom code.
Providing a built-in mechanism for this is very low on our priority so don't expect it anytime soon.
For the sake you have to upload each library as separately on maven and use its implementation in parent library modules till the main library module. Only then when you publish your main library on maven will include your all child dependencies.
As far as we have only one option add aar as api dependency inside the module.
For that we have to generate aar file and publish it to Maven and make it accessible by another module and consume it in app.
https://developer.android.com/studio/projects/android-library
As mentioned above android developer document.
The library module with source code is copied to your project, so you can actually edit the library code. If you want to maintain a single version of the library code, then this is probably not what you want and you should instead add the compiled AAR file as described above.
If there anything else we can do, please let us know by jot down in the command section.
It is not supported
It is not recommended to include one library into another because it leads to a serious issues with managing versions and complexity of creating and supporting such solution.
You should stick to native approaches like dependency manager or rearchitect your codebase
[iOS Umbrella framework]
I'm using Gradle in my Android project,and I have added some dependencies in build.gradle file.For some reasons,I want to point to the latest commit for one of my dependencies.For example:
dependencies {
...
compile 'com.github.ozodrukh:CircularReveal:1.1.0#aar'
}
I'm specifying CircularReveal's version to be 1.1.0#aar,and I know currently it has fixed some bugs but have not released it yet.How can I specify a commit in Gradle?I know some basics about Cocoapods,and it can be done like this:
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => '082f8319af'
Can it be done in Gradle? Any help would be greatly appreciated.
You can not do this directly from Gradle, but there are Gradle plugins and tools you can use to achieve this.
You can do this using Jitpack, an external tool. All you need to do is specify Jitpack as a repository:
repositories {
maven {
url "https://jitpack.io"
}
// Define your other dependency repositories, if any
}
Then include your dependency:
dependencies {
compile 'com.github.ozodrukh:CircularReveal:25aeca505d'
// Include your other dependencies, if any
}
You can also use use the gradle-git-repo-plugin from Layer, but I haven't tried this one yet. An advantage(?) of this plugin is that it clones the repository on your local machine and adds it as a dependency from there.
Ugo response is probably the correct one, here's an alternative for some specific cases:
dependencies {
...
compile 'com.github.ozodrukh:CircularReveal:1.1.+#aar'
// or 1.+ or even just +
}
That puts you on the latest version, no matter which one it is. Now, if you repository builds on a CI environment and deploys snapshots to Sonatype or a similar service, you can do
repositories {
maven {
url "https://project.sonatype.io"
}
}
And along with the other change you'll end up in the -SNAPSHOT versions. This behaviour reports warnings on build because your builds will not be reproducible, but that's a given if you're targeting CI versions.