How to Add and Use an AAR in AndroidStudio Project - java

I am trying to use a custom aar in my android project. I found dozens of examples in StackOverflow and the Web. Many failed at build, none worked. The clearest was at
http://kevinpelgrims.com/blog/2014/05/18/reference-a-local-aar-in-your-android-project/
That came closest to working.
Here's what I did
Successfully created a very simple AAR (Ref.aar) from Ref.java
// Ref.java
package com.ramrod.Ref;
public class Ref {
// Square an integer
public static int
square(int val) {
return (val * val);
}
}
Created a test project (RefTest)
Created folder 'libs' under RefTest/app
Added Ref.aar to libs
File->New->New Module->Import .JAR/.AAR Package.
Selected Ref.jar as filename->Finish (appeared successful).
Modified build.gradle
// build.gradle (Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.ramrod.RefTest"
minSdkVersion 11
targetSdkVersion 15
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile( name:'Ref', ext:'aar' )
}
}
Sync build.gradle (all)
Added reference to Ref.aar method (square) to onCreate in RefTest main activity.
int sq = Ref.square( 2 );
Build->Clean then Build->Rebuild.
This produced error: cannot find symbol variable Ref
I'm sure I'm doing something naive or just plain dumb, but I can't see it.
Any help appreciated.

You should:
1) create aar library and just put it in libs directory ( without "File->New->New Module->Import .JAR/.AAR Package" )
2) add to build.gradle (Module: app)
dependencies {
...
implementation fileTree(include: ['*.aar'], dir: 'libs')
...
}
After that you can use Ref.square(int);
Your apk will contain after build:

When you import an AAR from built in helper tools using Import aar/jar option,
studio creates a module with this aar.
So at this state you can see something similar to the state mentioned below.
When display panel is Android,
Change your panel mode to Project and open your testaar , you can actually see a build.gradle file for your module and the corresponding aar.
That is why your statement
compile( name:'Ref', ext:'aar' )
was not working.
To add this aar to your project(after using import aar/jar), what you can do is to first add the module to the settings.gradle (Project settings file)
include ':app', ':testaar'
then directly add to your application level build.gradle file
implementation project(':testaar')
2)Another way is to
Right-click on your Application Module ->Select Open Module Settings -> Select the Module -> Go to Dependencies tab
P.S you can also open this window from Build->Edit Libraries and Dependencies
You will come across a window as below
Click on the small + icon, then Module option and finally add the required module(testaar)
Sync your code and voila it will start working now.

Related

Android Studio `Plugin with id 'com.android.application' not found` [duplicate]

This is my first attempt at Android Studio. I installed 0.8.0 and updated to 0.8.2. As soon as a project is created I get the error message:
Error:(1, 0) Plugin with id 'com.android.application' not found
C:\Users\Bob\AndroidStudioProjects\HelloAgain6\app\build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.bob.helloagain6"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
and C:\Users\Bob\AndroidStudioProjects\HelloAgain6\build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Updated Answer (Dec. 2, 2020)
Latest Gradle: 6.5
Version check:
./gradlew -v
How to update:
Set URL: ./gradlew wrapper --gradle-version=6.5 --distribution-type=all
Update: ./gradlew wrapper
Latest Android Gradle Plugin: 4.1.0
If you add the following code snippet to the top of your build.gradle file. Gradle will update the build tools.
buildscript {
repositories {
google() // For Gradle 4.0+
maven { url 'https://maven.google.com' } // For Gradle < 4.0
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
}
Read more here: https://developer.android.com/studio/build/index.html and about version compatibility here: https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle and https://dl.google.com/dl/android/maven2/index.html.
Original Answer
I had this same error, you need to make sure your Gradle version is compatible with your Android Gradle Plugin.
The latest version of Gradle is 2.0 but you need to use 1.12 in order to use the Android Gradle Plugin.
This can happen if you miss adding the Top-level build file.
Just add build.gradle to top level.
It should look like this
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.xx.y'
}
}
allprojects {
repositories {
mavenCentral()
}
}
In my case, I download the project from GitHub and the Gradle file was missing. So I just create a new project with success build. Then copy-paste the Gradle missing file. And re-build the project is working for me.
Root-gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:x.x.x'
}
}
allprojects {
repositories {
jcenter()
}
}
Gradle-wrapper.properties file:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-x.x-all.zip
In the project level build.gradle file, I have replaced this line
classpath 'com.android.tools.build:gradle:3.6.3'
with this one
classpath 'com.google.gms:google-services:4.3.3'
After adding both of those lines, and syncing, everything became fine.
Hope this will help someone.
I am writing this not as a solution meant for many, but for some people who may commit a simple mistake like specifying the wrong url for importing projects from SVN. It is intended for those guys :)
This happened to me when I imported the project from SVN -> automatic prompt by Studio to open the project -> It asked for Gradle location -> D:\Software\Android\gradle-2.5 -> Then the error.
The same project in a different SVN branch works fine with the Gradle plugin and Gradle which I have configured in Studio. I tried changing Android Gradle plugin and Gradle to get it working on the erring branch without any success.
Finally, I figured out that it was my following mistake:
I tried importing a specific Application alone instead of importing the application along with dependent library projects.
The url which I used for import initially had the Application porject's name at the end. Once I removed it, and specified the parent directory which contained both application project and its dependent project, everything went smooth :)
I found the problem after one hour struggling with this error message:
I accidentally renamed the root build.gradle to filename in builde.gradle, so Android Studio didn't recognize it anymore.
Renaming it to build.gradle resolved the issue!
I still got the error
Could not find com.android.tools.build:gradle:3.0.0.
Problem: jcenter() did not have the required libs
Solution: add google() as repo
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.0"
}
}
I was using IntelliJ IDEA 13.1.5 and faced with the same problem after I changed versions of Picasso and Retrofit in dependencies in build.gradle file. I tried use many solutions, but without result.
Then I cloned my project from remote git (where I pushed it before changing versions of dependencies) and it worked! After that I just closed current project and imported old project from Gradle file to IntelliJ IDEA again and it worked too! So, I think it was strange bug in intersection of IDEA, Gradle and Android plugin. I hope this information can be useful for IDEA-users or anyone else.
Go to your grade file where you can see this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
And change classpath to this:
buildscript {
repositories {
jcenter()
}
dependencies {
// classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle-experimental:0.7.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
The other answers didn't work for me, I guess something wrong happens between ButterKnife and 3.0.0 alpha5.
However, I found that when I annotated any one sentence, either BUtterKnife or 3.0.0 alpha5, it works normally.
So, you should just avoid the duplication or conflict.
For future reference: For me, this issue was solely caused by the fact that I wasn't running Android Studio as administrator. I had the shortcut on Windows configured to always run as administrator, but after reinstalling Android Studio, the shortcut was replaced, and so it ran without administrator rights. This caused a lot of opaque errors, including the one in this question.
This issue happened when I accidently renamed the line
apply plugin: 'com.android.application'
on file app/build.gradle to some other name. So, I fixed it by changing it to what it was.
[FOR FLUTTER] go to your build Gradle then check if you have three paths
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
I somehow removed the android tools classpath and was getting the error.
This just happened to me using Android Studio 1.3.2, however, since I had just created the project, I deleted it and created it again.
It seems that it had not been properly created by Android Studio the first time, not even the project folders where as expected.
If you run a the module task with android plugin 1.2.3 in module directory , the problem appears. Try this:
../gradlew -b ../build.gradle -c ../settings.gradle :module:xxx
Make sure your two build.gradle and settings.gradle files are in the correct directories as stated in https://developer.android.com/studio/build/index.html
Then open "as existing project" in Visual Studio
Gradle is very finicky about this.
I got this error message after making the following change in my top-level build.gradle to update to the latest version of gradle:
//classpath 'com.android.tools.build:gradle:2.3.2' old
classpath 'com.android.tools.build:gradle:2.3.3' //new
I foolishly made the change while I was connected behind a hostile workplace proxy. The proxy caused the .jar files for the new version of gradle to become corrupt. This can be verified by inspecting the jars to see if they are an unusual size or whether they can be unzipped.
In order to fix the mistake, I connected to my network at home (which is not behind a proxy) and did a refresh dependencies from the Terminal:
./gradlew --refresh-dependencies
This caused the newer version of gradle to be re-downloaded and the error no longer occurs.
Check the spelling, mine was 'com.android.aplication'
This may also happen when you have both settings.gradle and settings.gradle.kts files are present in project root directory (possibly with the same module included). You should only have one of these files.
i had similar problem and i did following things to resolve it.
i referred to https://developer.android.com/studio/build
and copy / pasted these following lines before apply plugin lines
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
}
}
module app build.gradle file
apply plugin: 'com.android.application'
model{
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig.with {
applicationId "com.iamsafe"
minSdkVersion 15
targetSdkVersion 23
}
buildTypes {
debug {
minifyEnabled = false
useProguard = true
proguardFiles.add(file('proguard-rules.txt'))
}
}
}
}
dependencies {
compile 'com.android.support:support-v4:23.0.2'
compile files('libs/asmack-android-8-0.8.10.jar')
compile files('libs/commons-io-2.0.1.jar')
compile files('libs/httpclient-osgi-4.2.1-sources.jar')
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpmime-4.1.2.jar')
}
project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.10'
}
}
allprojects {
repositories {
jcenter()
}
}
In this case of issues check below code
dependencies {
classpath 'com.android.tools.build:gradle:**1.5.0**'
}
and gradle-wrapper.properties inside your project directory check below disctributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip
If these are not compatible with each other then you end up in this issue.
For com.android.tools.build:gradle:1.5. you need a version at least 2.8 but if you switch to a higher version like com.android.tools.build:gradle:2.1.0 then you need to update your gradle to 2.9 and above this can be done by changing distributionUrl in gradle-wrapper.properties to 2.9 or higher as below
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
If you work on Windows , you must start Android Studio name by Administrator.
It solved my problem
Just make sure you put the http and https proxy correctly when you create the app

Android Studio - include and consume .so library

I need to use some native libraries(.so) in my android project. According to some answers here in StackOverflow about this topic, I created a jniLibs folder in app/src/main and put there my files:
armeabi/my_lib.so
armeabi-v7a/my_lib.so
x86/my_lib.so
Then, in my activity class I use:
static {
System.loadLibrary("my_lib");
}
But when I run the app, an UnsatisfiedLinkError exception is generated. If this is important to be noticed, I don't have an Android.mk file, and I haven't changed anything that has to do with this in my gradle files. So, the only think I did is to copy-paste my .so files in jniLibs and to write the code above in my activity. So what might be the cause of this problem? Am I missing something?
EDIT
This is my gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 15
buildToolsVersion "23.0.3"
compileOptions.encoding = 'ISO-8859-1'
defaultConfig {
applicationId "my.package"
minSdkVersion 4
targetSdkVersion 4
ndk {
moduleName "my_so_lib"
}
}
sourceSets {
main {
jni.srcDirs = ["libs"]
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable true
}
}
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a', 'mips', 'armeabi'
universalApk false
}
}
}
Solution 1
Create Folder "jniLibs" inside "src/main/"
Put all your .so libraries inside "src/main/jniLibs" folder
Folder structure looks like :
|--app:
|--|--src:
|--|--|--main
|--|--|--|--jniLibs
|--|--|--|--|--armeabi
|--|--|--|--|--|--.so Files
Can you please confirm that you have this hierarchy ?
No extra code requires just sync your project and run your application.
Reference
https://github.com/commonsguy/sqlcipher-gradle/tree/master/src/main
Solution 2
Add both code snippets in your module gradle.build file as a dependency:
compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
How to create this custom jar:
task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
from fileTree(dir: 'libs', include: '**/*.so')
into 'lib/'
}
tasks.withType(Compile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
source
Thank you guys for helping but it was a stupid problem. When I imported my .so files under jniLibs, they were named like libSONAME.so. In these lines of code:
static {
System.loadLibrary("libSONAME");
}
we should not use System.loadLibrary("libSONAME");, but just System.loadLibrary("SONAME");.
Then, just build the project and everything was OK.
Thank you all for helping. I hope this will save time to someone else.
What is your gradle version? If you have a 0.7.3 or a newer version then the next article should help you:
Click here!

Gradle Android Maven Plugin doesn't create the pom file automatically

I would like to know how to create a pom file with "Gradle Android Maven Plugin".
I followed the steps on http://www.gradle.org/docs/current/userguide/maven_plugin.html (chapter "Convention Methods"). I also created the directory "buildDir" and get no errors. The App was build successfully but nevertheless the pom file doesn't exist. I am using Android Studio IDE.
Is it possible that the newpom.xml file exists on runtime only and does not exist in my project folder buildDir after runtime? Maybe I am looking for something which can't be found.
My app/build.gradle looks like this:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
apply plugin: 'maven'
task writeNewPom << {
pom {
project {
inceptionYear '2008'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
}
}.writeTo("$buildDir/newpom.xml")
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:appcompat-v7:+'
compile files('libs/retrofit-1.5.1.jar')
}
Can someone tell me if I missed something? :)
Best Regards,
Philip
No need to create buildDir manually, it has default value and refer to /build folder that place in same folder as build.gradle file.
Did you run follow command?
gradle writeNewPom
after run it I got newpom.xml file in projectroot/build folder, BUT it contains no dependencies however I have dependencies in build.gradle file.

Gradle: how do I include a local jar from a dependent java project in an Android build?

In my Android app, I'm getting a java.lang.NoClassDefFoundError when the code that references code in a dependent .jar is executed. My project includes an Android module as well as a java-only library module, which is where the jar dependency is. I'm using gradle 1.10 to build the project. Here is my project layout:
myProject
- app (Android)
- src
- build.gradle
- lib (java)
- src
- libs
- local-dependency.jar
- build.gradle
- build.gradle
- settings.gradle
The main project build.gradle is blank while the main project settings.gradle looks like:
include ':app', ':lib'
The Android app build.gradle looks like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "19.0.2"
defaultConfig {
minSdkVersion 18
targetSdkVersion 18
versionCode 1
versionName "1.0"
}
}
dependencies {
compile project(':lib')
}
The library build.gradle is:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile <some-dependency-in-maven>
compile files('libs/local-dependency.jar')
}
Everything compiles and packages with no errors and I'm not seeing any errors in the IDE (IntelliJ 13). For some reason, my local-dependency.jar is not getting added to the dex-ing process during the Android compile. Any maven dependencies specified in the lib project get added to the Android .apk just fine; it's just my local jar dependency. Is there something I'm missing?
Thanks!
This is not directly possible as local jars are not declared as transitive dependencies in Gradle.
You have two options:
merge the two jars in your java library so that the output contains the local jar.
create a different project with no source, only the jar, and make the project depend on it.
The second option gives you the ability to have more than one project depend directly on the local jar (on top of it becoming a transitive dependency). To do it, create a new gradle project and just put in its build.gradle the following:
configurations.create("default")
artifacts.add("default", file('somelib.jar'))
This simply register your jar as the default artifact published by the project and this will get consumed by the other projects.
In recent (4+, IIRC) versions of gradle, you can achieve this with the following configuration:
compile (project(':ProjectIDependOn')) {
transitive = true
}
Setting transitive to true when depending on another project will expose all of that project's libraries to this project.

How to create your own library for Android development to be used in every program you write?

I am a Delphi programmer and have written, over the years, hundreds of classes and routines which I can use in every Delphi program I write.
This library is called dlib and can be used in every Delphi program by putting this folder in my library path and using one of the units in the uses section of a Delphi unit.
Being completely new to Java and Android development, I am wondering how to do this in similar way.
So my question, how can I write own classes, put them in some global folder, and use these classes and routines in every Android program I write ?
I know this is a basic question, which I can probably find out by searching Google and trying it out in Eclipse, but if someone can put me on the right track, I know I will save much time.
Thanks.
You have to create Android Library Project.
Create android project in Eclipse, enter Project Properties -> Android and check isLibrary property. Now you can add this library to your Android Application project by adding it to list on the same property page.
More detailed instructions here in Working with Library Projects section
Instructions for creating a library in Android Studio:
Create a library module
To create a new library module in your project, proceed as follows:
Click File > New > New Module.
In the Create New Module window that appears, click Android Library, then click Next.
There's also an option to create a Java Library, which builds a traditional JAR file. While a JAR file is useful for many
projects—especially when you want to share code with other
platforms—it does not allow you to include Android resources or
manifest files, which is very useful for code reuse in Android
projects. So this guide focuses on creating Android libraries.
Give your library a name and select a minimum SDK version for the code in the library, then click Finish.
Once the Gradle project sync completes, the library module appears in
the Project panel on the left. If you don't see the new module
folder, make sure it's displaying the Android
view.
Convert an app module to a library module
If you have an existing app module with all the code you want to
reuse, you can turn it into a library module as follows:
Open the module-level build.gradle file.
Delete the line for the applicationId. Only an Android app module can define this.
At the top of the file, you should see the following:
apply plugin: 'com.android.application'
Change it to the following:
apply plugin: 'com.android.library'
Save the file and click Tools > Android > Sync Project with Gradle
Files.
If your library is in .java files composed of java code. There's a really detailed tutorial of how to use the library at mobile.tutsplus.com. Link below:
http://mobile.tutsplus.com/tutorials/android/android-essentials-creating-android-compliant-libraries/
For Example I wanted to use the Pull To Refresh library by Chrisbanes at Github.com here https://github.com/chrisbanes/Android-PullToRefresh/tree/master/library. The library's structure is in the form of an Android app. It has the form like below:
res/
src/
AndroidManifest.xml
pom.xml
project.properties
How to use on Eclipse:
Create new project in Eclipse. Give a name to your project. Select
"Create project from existing source". Select the location of the
root folder containing the above mentioned files in "Location".
Select your target and click finish.
Select properties of the newly project you created. Select "Android"
option. Select the "Is Library" checkbox if it's not already
selected. close properties.
Add a reference to the library from the project that is going to use
this library. Select your project that uses this library. Open
Properties. Select "Android" option. At the bottom on the "Is
Library". Don't select checkbox of "Is Library". Click "Add" button
on the right. Your project that you created on step 1 and 2 should
be listed ready for selection. select it and click apply. close
properties.
You're ready to reference the classes from your project.
With java, you create a Java Archive (jar) that contains all your classes (*.class files) of that library and the jar file is your library.
To use it, simply add it to the classpath.
(For "jar" and "classpath": basic Java concepts, please use google to find tutorials, you'll have to understand those concepts anyway, the sooner, the better ;) )
Convert all of your class in Java and make a jar file. Use this jar in your android project by copying in libs/ folder and then adding in to build path. Make a clean of project and then run it.
If you're using new android studio version and gradle 7.0.3
Android Studio Arctic Fox | 2020.3.1 Patch 3
Build #AI-203.7717.56.2031.7784292, built on October 1, 2021
Runtime version: 11.0.10+0-b96-7249189 amd64
VM: OpenJDK 64-Bit Server VM by Oracle Corporation
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 2
Registry: external.system.auto.import.disabled=true
Creating module
Create new project with empty activity
Click file -> new -> new module -> and choose android library.
After new module created you can add java class or something for
your library
Export library to AAR file
You can check this for more information
Export library to jitpack.io
Set this file like this
build.gradle (project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (module:app)
plugins {
id 'com.android.application'
}
android {
lintOptions {
abortOnError false
}
}
android {
compileSdk 31
defaultConfig {
minSdk 16
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
build.gradle (module: YourLibraryName)
plugins {
id 'com.android.library'
id 'maven-publish'
}
task androidSourcesJar(type: Jar) {
classifier 'sources'
from android.sourceSets.main.java.srcDirs
}
project.afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId 'com.github.YourGithubUsername'
from components.release
artifact androidSourcesJar // optional sources
}
}
}
}
android {
compileSdk 31
defaultConfig {
minSdk 16
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Create file jitpack.yml in root project (YourProjectName -> Gradle -> right click -> new -> file -> name it "jitpack.yml" and put this code to jitpack.yml file
jdk:
- openjdk11
before_install:
- chmod +x gradlew
install:
# - ./gradlew build :lib:publishToMavenLocal
- ./gradlew build publishToMavenLocal
Share your project to Github
Visit jitpack website
Follow this step for upload your library

Categories

Resources