I am trying to create .aar file from Android Studio. The code I have written needs appcomapt v7 library. I don't want to add the dependency in the build.gradle file of my aar package but want it to take from the project it is added. Please suggest how to do it ?
Thanks.
You need to add it to your library module to use all the classes that Android needs, if your library doesn't use any of those classes, then you can make a jar library.
Now, when you compile your library in the app module, you can exclude the library dependency adding this to the compile line
compile('com.yourpage:yourlibrary:1.0.0'){
exclude module: 'appcompat-v7'
}
I don't want to add the dependency in the build.gradle file of my aar package
You have to include it there, otherwise you can not compile your aar
but want it to take from the project it is added
You can still do that:
If your library declares appcompat-v7 version 23 and your app does not declare appcompat-v7, version 23 will be used in your app.
If your library declares appcompat-v7 version 23 and your app declares appcompat-v7 version 24, version 24 will be used in your app.
Related
I know the way using 'flatDir'.
But android studio warn do not use flatDir.
My project is android library.
I add jniLib in sourcet and use implementation files.
Then, I could add direct aar dependency to my lib and app which use my lib.
But I can't add dependency to androidTest in my android library project.
I want to use androidTestImplementation but my project is multi flavor build and there is no API flavor[Debug|Release]AndroidTestImplementation with files arguments.
I tried to search the way, but failed.
Now, I use flatDir and ignore warning.
How can I solve this problem?
I have two projects that use the same library. This library uses a jar file as a dependency, however only the library is able to read the classes from the jar file. The two projects don't have access to the classes from the jar file.
I tried adding the jar file to the two projects separately, but I get a build error, probably because now it's included in the project level and library level resulting in conflicts.
The jar file is YouTubeAndroidPlayerApi.jar
/------------------- Project1 (can't read classes from jar)
Library(w/ jar)
\------------------- Project2 (can't read classes from jar)
Any ideas on how to approach? Thanks!
If you are using gradle 4.1, make sure to use the api keyword when importing the .jar into your library. Then remove it from your other projects.
for example: api fileTree(dir: 'libs', include: ['*.jar'])
from the documentation:
When a module includes an api dependency, it's letting Gradle know that the module wants to transitively export that dependency to other modules, so that it's available to them at both runtime and compile time. This configuration behaves just like compile (which is now deprecated), and you should typically use this only in library modules. That's because, if an api dependency changes its external API, Gradle recompiles all modules that have access to that dependency at compile time. So, having a large number of api dependencies can significantly increase build times. Unless you want to expose a dependency's API to a separate test module, app modules should instead use implementation dependencies.
An Android app uses a library (aar module) that uses "com.google.gson.Gson". The library has the following in its build.gradle:
compile 'com.google.code.gson:gson:2.6.2'
The app builds fine, but generates the following error when it starts:
Failed resolution of: Lcom/google/gson/Gson;
The only way to solve it is adding the same compile line to the app's build.gradle:
compile 'com.google.code.gson:gson:2.6.2'
Could anyone shed some light on this?
[Edit]
The library was added with the standard procedure that created a folder under the app called "androidLibrary-release". The following line has been added to the build.gradle of the app:
compile project(':androidLibrary-release')
Libraries don't include their dependencies. It is up to the developer to include them as necessary in the app modules that implement them. However, if this library comes from a Maven repo, it is possible to include the information about which dependencies the library uses and they will be fetched when your project is built.
For example if I depend on the Android Support Library, I add this line in the build.gradle:
dependencies {
...
compile "com.android.support:support-core-utils:24.2.0"
}
My questions are:
Where does the "support-core-utils" and version code is defined in
the support library?
What's the benefit of specifying the lib name and version
code?
The : is a separator used in the shortcut definition of an external library.
dependencies {
...
compile "com.android.support:support-core-utils:24.2.0"
}
stands for
dependencies {
...
compile group: 'com.android.support', name: 'support-core-utils', version: '24.2.0'
}
Here is some documentation.
About the Support library, you can read the support library features list in order to know which part of the support library to add to your project (instead of adding everything and ending with a huge APK :) )
To my mind, the benefit of specifying the version code, is to allow a developer to only update to the last version of a library, when he is sure that his code is compliant with the last changes in this library.
What does the “:” mean in gradle android dependency package name?
Where does the "support-core-utils" and version code is defined in the support library?
: is a separator to enable you to declare a maven dependency group ID, artifact ID and version in a concise way. All three are required to identify a dependency in a maven repository.
Android SDK manager installs a local maven repository ("Android Support Repository") where the actual versions of the support libraries are found.
What's the benefit of specifying the lib name and version code?
The build tooling can find your dependencies and successfully build code that depend on such libraries.
I want to use this library in my Android Studio project https://github.com/SimonVT/android-numberpicker. I can't for the life of me figure out how to add it to my project. Can someone just outline how this would work? I've only ever added libraries that were contained in jar files.
In build.gradle, use:
dependencies {
compile group: 'net.simonvt', name: 'android-numberpicker-parent', version: '1.0.0'
}
If you are using new gradle build system (and you really should), just add
compile 'net.simonvt:android-numberpicker:1.0.0'
to your build.gradle's dependencies section.
I found a forked version of this library which can be imported from source as a module in Android Studio. It is available here:
https://github.com/heavyplayer/android-numberpicker