how can I delete an external library from Android Project using Android Studio ? In my gradle script I have :
def neo4jVersion = "2.1.7"
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile "org.neo4j:neo4j:${neo4jVersion}"
}
This is pulling about 15 jars but I need to delete one of them, each time I do it, it deletes it but when I run the project again it reappears ! How to delete it permanently ? This is screenshot
The geronimo library is the dependency of the Neo4j kernel.
You can't get rid of it without messing up the whole library.
Related
WHAT I WANT :smile: :
building kotlin library,
deliver it as an .aar file
Java project that uses my .aar don’t need configure anything, just include my .aar and start playing.
first Q : IT THAT EVEN Possible ? cause i’m loosing hope :smile:
if the project that uses my library doesn’t have Kotlin configured, then it says ClassNotFoundException.
-WHY IS THAT ?
if kotlin have the same byte code as Java byte code, (and 100% compatible),
then why i need to have kotlin when using .aar writen in kotlin in a JAVA Project ?
After some reaserch, i discovered that i must include kotlin runtime library in my project but i don’t know how,
i’ve allready tried basically all the solution overs the net ,
i think fat aar isn’t supported on Android,
Thank You All for your attention.
Update
in my aar project i have a module with the following build.gradle
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
/////
.
.
dependencies {
////
.
.
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
in my application that uses the .aar
i have the following in project build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
in the build.gralde module
implementation(name: 'my-aar-library', ext: 'aar')
and when i run the app, it crash and here is the stack :
09-25 15:14:22.814 3239-3239/com.example.mymodule E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mymodule, PID: 3239
java.lang.NoClassDefFoundError: kotlin.jvm.internal.Intrinsics
at com.com.example.mymodule.views.MyCustomView.<init>(PCMajorHeadereView.kt)
at .
.
.
.
.
.
UPDATE 2 :
PS :
clearly i must add the kotlin runtime-library to my .aar
i tried all over the net, it doesn’t work :'(
Final Update :
solution found thanks to cilling,
note that you must include the runtime-library into the local maven repo,
it can't access online content
Thnx for all
The problem is that your aar doesn't include dependency tree (.pom file), so Gradle is not able to download them during the sync.
So, what's the proper solution? You should use repository manager, like Maven.
You can see #Robyer post how to include all dependencies and publish it on MavenLocal:
https://stackoverflow.com/a/42160584/7508302
That post is about providing source code for library, but there is also ready to use gradle publish script.
Then, in your 'local maven' a library will be published.
And then, you can add to your gradle file (in project you want to use that library): repositories { mavenLocal() } and then add dependecy like this:
implementation ('com.example.android:library:0.0.1-SNAPSHOT#aar') {
transitive = true
}
Full instruction:
1) In your library add a gradle file responsible for publishing on mavenLocal(). See https://stackoverflow.com/a/42160584/7508302 for details
and ready to use script.
2) Push the library to mavenLocal. It's a local maven repository. You don't need to install anything, as the maven repository just has to have proper dir structure.
3) Check mavenLocal dir. There should be a dir tree with your domain name, for example: com -> mycompany -> library -> 0.0.1 and in that folder you should find .pom file. Open it, to see dependencies of your library.
4) Add mavenLocal() to your repository section in project level gradle file. Note, that mavenLocal just points to some place in your files.
5) Add library dependency using just qualified name (for example: com.mycompany:library:0.0.1#aar. Add parameter transitive if you want to fetch transitive dependencies (that transitive parameter means that that library may depend on other modules).
That way gradle should fetch declared dependencies and include them to project.
Call the below call for smile.aar file in build.gradle file.
implementation project(':smile)
Assuming that smile is the .aar file name.
If you want to run Kotlin you must include following in project build.gradle
buildscript {
ext.kotlin_version = '1.3.31'
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
and also include these in app level build.gradle
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
//in dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
I have some code I'd like to use across multiple different projects. Let's say it's some e-commerce code that handles things like payments and shopping carts.
It seems inefficient and dangerous to copy-paste everything across different projects. And if I add one feature or fix one bug in the core e-commerce module, I'd like that change to be reflected in other projects using it too.
I would also like to re-use some of the Activities, Fragments, Adapters too.
What is a good approach to this?
When we have a library project that needs to be shared to every project on a local computer, we can make use of Maven.
A. Here the step in your library that we will you for the project:
Make a library project from Android Studio.
Add Gradle Android Maven plugin to root build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
Add apply plugin for step 1 in your library build.gradle. (NOT root build.gradle):
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
Add the following after the apply plugin, this line to determine your library when adding to project:
group = 'com.yourpackage.yourlibrary'
version = '1.0'
Add the following code in your settings.gradle:
rootProject.name = 'yourlibrary'
Then publish it to your local maven with:
./gradlew install
Or you can use gradle option in Android Studio.
Your library will be installed in $HOME/.m2/repository. Remember that to use the library you need to add like this:
Groupid:artifactid:versionid
Artifactid will be package name of your library.
B. Here the step in your Project which using the library:
Add the following code in your root build.gradle:
mavenLocal() // for local maven.
This for getting the local library maven that we have installed in step A
Then in your app project.gradle, add compile for the library:
compile 'com.yourpackage.yourlibrary:yourlibrary:1.0'
Read more:
Gradle: How to publish a Android library to local repository
https://github.com/dcendents/android-maven-gradle-plugin
https://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en
From my Knowledge 1. As others said try creating your own Module or Library and use it where ever you need 2.Use Version Control Tools Like Git(If your code changes it will be refleted in your git account)
I have created Android library as Android Studio module. Added as dependency to my root module. While coding I can import any class from library package but while I'm trying run the application I'm getting an error package some.mylibrary.project does not exist.
build.gradle root module
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:5.+'
compile project(':libraries:mylibrary')
}
android {
compileSdkVersion 17
buildToolsVersion "20.0.0"
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
abortOnError false
}
***
}
build.gradle library module
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'idea'
android {
compileSdkVersion 17
buildToolsVersion "20.0.0"
*****
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
settings.gradle
include ':libraries:mylibrary'
P.S. I have to mention that the project was exported from Eclipse IDE so the project structure is different from default one.
For Android Studio 2.2.2
Yes, in library module, it can't use the apply plugin: com.android.application statement in the module definition, yes, use apply plugin: com.android.library instead. (still in lib module)
But then you have to do the following:
Expose the same SDK versions in Gradle files for both modules.
Right click on your projects "app" module folder and click on -> open module settings
Click on the "dependencies" tab
Click on the + sign to add a new dependency and select "Module Dependency"
Look for the library you need and add it.
Also while naming your lib module avoid capitals.
If you have a library module, it can't use the apply plugin: 'com.android.application' statement in the module definition, or the build will silently fail as you're seeing. use apply plugin: 'com.android.library' instead.
A bug has been filed to request that the build system fail loudly instead of silently when this happens: https://code.google.com/p/android/issues/detail?id=76725
The answer above is somewhat lacking
If you project java add in Kotlin getting get this error
Tools Tab Kotlin and Configure Kotlin
(Select Android with Gradle) after select with Modules
Project build.gradle add
ext.kotlin_version = ‘1.3.21’
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Apps build.gradle
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Referance : https://medium.com/mindorks/enabling-kotlin-support-for-a-current-only-java-android-project-98c75e04384a
This error happens when you change the package name and try to run the code. this occurs because the android studio still has the cache of your package with an old name.
Also, cross-check all the imports as well as an imported package in your code so that no different package name exists. For example, is common this error is referring to another imported file near where the error is occurring. Check previous imports near.
To fix this error you can try to do an 'invalidate caches / Restart' option from the File menu in android studio. Choose “Invalidate and restart option” and close Android Studio.
Another reason for this error, is when one changes the project's path root folder or in any of the modules it depends. In this particular case, to fix this error you need to remove the affected modules, and re-add them again. Next don't forget to do an 'invalidate caches / Restart' option from the File menu in android studio. Choose “Invalidate and restart option” and close Android Studio.
Clean your project from android studio :
“Build -> Clean Project”. This will clear your build folders.
Remove your .gradle directory from the root of your project. It contains some Gradle cache files.
Delete also the .idea directory (make a backup before). It contains some project configuration files.
Restart Android Studio.
Finally
if the error still persists, you need to move the affected files to an external directory of the project's root folder. And on Android Studio, create manually each filename as previous, and copy the code inside from the old file. This will defiantly solve this error.
In build-gradle app, add this row:
implementation project(":your_name_library_here")
If you are facing this issue while using Kotlin and have
kotlin.incremental=true
kapt.incremental.apt=true
in the gradle.properties, then you need to remove this temporarily to fix the build.
After the successful build, you can again add these properties to speed up the build time while using Kotlin.
Reference: https://stackoverflow.com/a/58951797/3948854
I am trying to use this library [1] in an Android project either with Android Studio or with ADT. But it doesn't work at all. In ADT I don't know how to handle gradle stuff and in Android Studio, when I try to "Import Project", I get the error "Could not find com.google.android.gms:play-services:3.1.36.
(don't have enough reputation to post picture, it's on imgur with xswZ3.jpg)
I am not familiar with gradle and I only have a vague idea of what it does but all I want is to use something like BubbleIconFactory f = new BubbleIconFactory(this) in my own project.
Any help is appreciated!
[1] https://github.com/googlemaps/android-maps-utils
Perhaps your problem is needing the repositories outside of the buildscript block.
The repositories internal to the buildscript is for managing the gradle dependency itself, I believe. Here's how I resolved my problem with google-maps-utils as a library dependency. Hopefully this helps. I included my maps and support-v4 libs too.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// Support Libraries
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
}
com.google.android.gms:play-services:3.1.36 can be downloaded by going to your SDK Manager and installing the Extras->Google Repository package (you may want to install the Extras->Android Support Repository as well while you are there). These allow Gradle to automatically use these resources without the need for library projects or jars manually added to your project.
Add the following dependency to your Gradle build file:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.2+'
}
You'll need to install the "Google Repository" from the Android SDK manager.
See demo/build.gradle for an example.
You can, of course, copy the library directory and use it like any other Android library project.
Let me know if this helps!
Chris
Steps:
First File>Project Structure>Click Plus Button >Import Graddle Project>Select the file(library folder) from the location where downloaded>CLick Ok.
Add this code to dependencies to that app module build.gradle file(remember there are two build.gradle files) :
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.4+'
}
Copy gradle.properties file contents of that Android-maps-util Library project app(found inside that project library folder) TO
gradle.properties file of your project(Simple copy and paste of content to the editor).
Click Sync Project with gradle files button. And you must be fine!
I have a native lib in the
/libs/armeabi folder called libparser.so
and an associated jar file.
I changed the gradle build file to include the jar file, which seemsm to be easy (MYNEWJAR):
dependencies {
compile files('libs/android-support-v4.jar', 'libs/MYNEWJAR.jar')
}
But when I run the app, I think it cannot find the native lib:
E/AndroidRuntime(22569): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load parser from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.hybris.mobile.history-1.apk,libraryPath=/data/app-lib/com.hybris.mobile.history-1]: findLibrary returned null
E/AndroidRuntime(22569): at java.lang.Runtime.loadLibrary(Runtime.java:365)
E/AndroidRuntime(22569): at java.lang.System.loadLibrary(System.java:535)
E/AndroidRuntime(22569): at com.senstation.android.pincast.Pincast.<clinit>(Pincast.java:1299)
E/AndroidRuntime(22569): ... 17 more
Can you help me get the build file straight so it will include the native lib? This seems to be happening automatically on Eclipse, but i really want to use android studio.
Thx!
Sven
I found this answer from user Assaf Gamliel very useful.
And just made some changes to make it even more cleaner.
You don't need to rename the .zip file to .jar, just add it with a normal compile file dependency on build.gradle script. So, you would make a foo.zip file with a structure similar to this:
foo.zip ->
|--/lib
|--|--/armeabi
|--|--|--*.so
|--|--/x86
|--|--|--*.so
put it in your libs folder and then add it to gradle using compile files('libs/foo.zip'):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+' //gradle plugin update for Andoid Studio 0.2.+
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/foo.zip') //zip file should be in Module's /libs folder (not the Project's /lib)
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
while gradle does the build it just unzip the file you added preserving its structure.
To use an external jar library
Put the jar into the libs folder/drag the file onto libs from a file explorer
Right click it and select Add as library
Ensure that compile files('libs/your_jar.jar') is in your build.gradle file
To do this, modify build.gradle which is under [projectname]Project -> [projectname] in the project pane on the left.
For me, it was necessary to change
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
to
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile files('libs/universal-image-loader-1.8.5.jar')
}
Click Rebuild Project under the Build menu.
I did this today to get the Universal Image Loader library integrated with my project.
Create a directory called 'jniLibs' into 'app/src/main/' and put inside all the .so
app/src/main/jniLibs/
|---- armeabi-v7a/your.so
|---- armeabi/your.so
|---- x86/your.so
Hmm...I was HOPING that someone will provide a clear example, of
how to make a 3rd-party JAR file accessible to Android-Studio, by
showing the exact SYNTAX of what the resulting 'build.gradle' file's
dependency-clause would look like, after they've added their 'foobar.jar'
entry.
You know, something like:
=========
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile 'org.somedevs.foobar:Foobar.jar'
}
=========
[Otherwise, I don't stand a snowball's chance in hell of
guessing what the answers posted so far really mean. My
INTITAL clause contained the single 'compile' line...so my
GUESS would that one should add another such line!?!?]
EDIT: Yes, many THANKS, rebelious! I now, too, have it working.
[Instead of the 'drag/drop' onto the 'libs' in Studio, I have more
reliable results by just right-clicking on 'libs' in Studio and choose
"add as library...", after copying the JAR into that location, using cmd-line.]
The correct form for the dependencies clause is the form shown below:
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile files ('libs/Foobar.jar')
}
Due to security reason, it's not possible to reference a local jar/aar file in an application project with the gradle android plugin.
For the support library, with the Android SDK Manager, you have to install the extra named Android Support Repository which will expose the support library inside a maven repository. Then you can add the support library in your project via :
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
For external libraries, you have 2 possibilities :
Build an aar file and deploy it to your local maven repository, then reference it in your project like you did with the android support library.
Put the library sources beside your application project and create a settings.gradle at root which will define the modules. (see the docs for more info).
On my side I would prefer build aar files because it's more modular.