I am having a problem with Android Studio recognizing classes inside an #aar library imported locally.
So... I've made a library and exported is an aar file. Inside android studio I selected Import Module and them Import .JAR or .AAR Package.
The project compiles and works with the classes inside the aar file but Android studio can not find the classes or offer any auto completion of so all.
Here is a few of screenshots:
The same problem also happens with other #aar libraries imported the same way:
Any suggestions?
Edit:
build.gradle:
...
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':UpPlatformSdk')
compile project(':simpleorm')
... // more libraries here
}
settings.gradle:
include ':app', ':UpPlatformSdk', ':wear', ':simpleorm'
Looks like you could do this How to manually include external aar package using new Gradle Android Build System
If you have them in your lib folder
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'UpPlatformSdk', ext:'aar')
}
This may not be the quickest way, but this works for autocompletion and also solved my problem of missing classes when I tried compiling my local AAR using the method #puj described. Essentially you need to create a local Maven repository to host the AAR, but any changes you make are pulled by the build system when you do a Gradle sync.
Android Library AAR depending on another library
Related
I would like to create my own library .aar library file, and add it to different projects as a dependency in gradle. Also, how can I add *.aar library with own gradle file in local repository?
If you are planning to release the lib, it will be better not to include the dependent libraries in the packaged aar and instead add the same compile dependencies found in lib build script inside the build script of the app as such:
app build.gradle:
dependencies {
compile ':my-lib'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.facebook.android:facebook-android-sdk:4.14.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.google.code.gson:gson:2.8.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
compile 'com.google.android.gms:play-services:11.0.4'
}
That way users of your library won't face merging conflicts when they use public libraries like your library does, gradle will automatically resolve them.
If you are looking looking for a better way to include all dependencies in a single library: Don't. Gradle cannot resolve merging conflicts if a aar contains a certain lib packaged inside while the app as well depends on the lib and contains code calling methods from lib
You can read more details here: Exclude jar-library from aar
And here Generate AAR file with all dependencies
So, I guess you should move your .aar file to lib directory in the project folder (create it if necessary). After that in your build.gradle file in dependency section write like that
dependencies {
...
implementation(name: 'your-library-name', ext: 'aar')
...
}
i write a javafx andoid application in netbeans with javafxports and gradle. I added the dependencies to gradel, but now i dont know how to add the jars to my project or to use it in my app-code. . .
Do you know how i can us it? I tried searching the www for hours ...
Ok i tried it but i dont get it ...
I did exactly what you said but netbeans still says:
package io.netty.bootstrap does not exist
I created a folder unter src/android/ called libs and add my jar there ...
Here are my dependencies:
dependencies {
compile fileTree(dir: 'src/android/libs', include: ['*.jar'])
compile files('src/android/libs/netty-all-4.0.29.Final.jar')
}
FINAL SOLUTION:
You have to add: compile 'io.netty:netty-all:4.0.24.Final' to the build.gradle file. (Example for netty JAR-Libary)
I copy the Libary (netty) to an Folder called "libs" in my main Folder not in sry and so on. Create the folder if not exist
Write your code and you will see, import works.
Thank you to José Pereda for the time and the final solution!
Based on the edited question, these are a few suggestions for working with dependencies on a JavaFXPorts project.
Dependencies and build.gradle file
According to this, the default dependency configurations compile and runtime are supported, and the jfxmobile plugin adds extra configurations for each supported platform like androidCompile or desktopRuntime.
To access third party dependencies, from a given repository this should be added:
repositories {
jcenter()
}
dependencies {
compile 'groupId:artifactId:version'
}
Since jcenter() is a superset of 'mavenCentral()`, you can use any maven dependency that was in the form of:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
as compile 'groupId:artifactId:version'. So in this case:
dependencies {
compile 'org.glassfish:javax.json:1.0.4'
}
Local files
Accesing local jars can be done using files:
dependencies {
compile files('lib/my-jar.jar')
}
having my-jar.jar at a lib folder inside your project, but outside the src folder.
If you want to add several jars:
dependencies {
compile fileTree(dir: 'lib', include: ['*.jar'])
}
Gluon plugin for NetBeans
After any change in the build.gradle file, it is necessary to reload the project, so the new changes are taken into account, and the new dependencies are retrieved.
Under the Projects view, right click on the Project root and select Reload Project.
Check also the Dependencies folders, those should contain the jars included in the build.
Since there are several of these folders, you can see for instance that Compile for android includes android.jarand jfxdvk-8u60-b3.jar. Compile for main should contain all the jars defined for compile.
Samples
These are some projects where the build.gradle contains dependencies, so they are a good way to start with JavaFXPorts.
HelloPlatform and other samples.
2048FX
SMSTracker
HelloCharm
In my project I am using SlidingUpPanel.
Due to a feature that I needed, I cloned the project to my machine and manipulated the library. I tested my feature on its demo project and everything is okay based on this project.
Now, I want to compile its library module in order to get .aar file and add it to my project. What I did is:
I opened cmd and navigated to root folder of slidingUpPanel project.
Ran this command: ./gradlew :library:build
Library compiled and created .aar under /library/build/outputs/aar/library-debug.aar
I copy/pasted this file into /libs folder of my project and updated build.gradle like this:
dependencies {
compile ANDROID_SUPPORT
compile CRASHLYTICS
compile 'com.facebook.android:facebook-android-sdk:3.20.0'
compile 'com.googlecode.libphonenumber:libphonenumber:7.0.1'
compile 'com.android.support:recyclerview-v7:+'
// Local libs not in Maven Central
compile files('src/main/libs/httpclientandroidlib-1.2.1.jar')
compile files('src/main/libs/nineoldandroids-2.4.0.jar')
compile files('src/main/libs/niftynotification-1.2.jar')
compile files('src/main/libs/zendesk-1.0.0.1.jar')
compile files('src/main/libs/library-debug.aar')
}
After I sync gradle file, I'm getting error which is because SlidingUpPanelLayout does not recognise.
Any idea why the library cannot be recognised? Any idea would be appreciated. Thanks.
So, first, lets add this kind of repository in our build.gradle file.
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
Here, I assume that your aar files will be stored in the libs folder in your project.
You can now add a dependency like
dependencies {
compile 'net.my.package:mylib:1.0#aar'
}
First, this is not duplicate. I have browsed answers to "How to add library to project in Android Studio" but found no answer. I cant find src and libs folder. I want to add volley jar to project. Screenshot attached:
http://i.stack.imgur.com/2SyUp.png
For preferred way read bellow this answer:
If you need to add a library to the Android Studio project navigate to your project folder with default path at:
\YourProjectName\app\libs
You can paste your *.jar library there. Make sure your build.gradle contain this directive at dependencies part:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
To see the library at the Android Studio, switch to the "Project" view at the menu:
Preffered way:
Preferred way to import libraries to your project is by gradle dependency system.
To do so, open your build.gradle file and locate the dependencies part. To import the library you mentioned, Volley, your dependencies part should look somehow like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.mcxiaoke.volley:library:1.0.10'
}
You don't need to import the *.jar library manually any more. Gradle dependencies system will take care of it.
To find gradle dependency you need, you might use tools like:
http://gradleplease.appspot.com/
http://search.maven.org/
I have a library project that I want to share as AAR file.
This library project contains several JAR files, some of them are classes I made and are used in the library project. For example I have a class in the lib project that inherits from a class inside the JAR file.
I was able to create the AAR file, and now I'm testing the AAR file in a sample app made in Android Studio.
I added the AAR file modifying the build.gradle file of the app module like this:
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(name: 'mightylibrary', ext:'aar')
compile 'com.android.support:appcompat-v7:20.+'
}
Then when I try to use methods from the parent class I'm not able to see them, only the methods implemented in the child class.
Is there any known limitation of accessing classes inside JARs packaged within a AAR file?
Any solution?
Thanks
So it seems I missed to add this
repositories {
jcenter()
mavenLocal() // Missed this
}
In the project (not the module) build.gradle file so it searchees in the local cache repo. What seems funny is then why it detected the classes within "classes.jar" but not in the other jars within "libs" folder of my AAR file. Interesting...