I am trying to implement Android-DirectoryChooser in my app, but I am new to Android Studio and I have come to a problem that I am not sure how to resolve.
I have created a new folder inside my project called "libraries" and I have copied this library project inside this folder. I then added a dependency like this:
compile project('libraries:android-directorychooser')
I then synced gradle and I have gotten the following error:
Error:(2, 0) Plugin with id 'android-test' not found.
This is probably the problematic line in the project library build.gradle file:
apply plugin: 'android-test'
I've searched for a plugin named "android-test" but I've only found a library and it seems to be deprecated. How can I solve this?
Know you for what this plugin is necessary? When not remove it and your robolectric dependencies.
Plugin comes from https://github.com/robolectric/gradle-android-test-plugin
Robolectric is for unit tests, when you like to use it.(which I would recommend) then just add something like that
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.+'
}
}
to your lib module build.gradle file and the plugin should be found
Android-test is no longer a separate plugin. The standard 'android' plugin now includes testing features. See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Testing for more information.
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'm basically following the migration guide from within Crashlytics (which is pretty much summarized in this post).
I followed the same instructions verbatim, you can see that from my git diff:
Yet when I sync my Gradle, I get this error:
5:02 PM Gradle sync failed: Could not find method compile() for
arguments [com.google.firebase:firebase-core:11.4.2] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Update
As mentioned in the comments (and as experienced by us at the end), we shouldn't migrate anyway until further notice:
Update 2
In fabric, if you click on Crashlytics, there is a link on the left nav bar that says Firebase, when you click on it you get this ad
The buildscript block is not a place for your application level dependencies. See this answer for more information on the buildscript block.
You need to place your compile or implementation/api(for gradle 3.4+ and android gradle plugin 3.0+) dependencies into the separate dependencies{} block with the rest of your dependencies, that is usually on the same level as your android plugin configuration.
In your project level grade file, you need to add, maven {
url 'https://maven.fabric.io/public'
} to the repositories.
add the following to your dependencies classpath 'io.fabric.tools:gradle:1.25.1''
In your app level Gradle file put apply plugin: 'io.fabric' below apply plugin: 'com.android.application' and under depencies place this implementation('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true
}
place apply plugin:'com.google.gms.google-services' at the bottom of the app level gradle file.
Change compile '...' to implementation '...'
You are using Google Services plugin 3.0.0. The instructions for adding the Crashlytics SDK indicate that 3.1.2 or higher is required:
Note: Crashlytics requires Google Services plugin version 3.1.2 or
higher. Check the com.google.gms:google-services version number in
your project's build.gradle dependencies.
I have been trying to link the local copy of Android Beacon Library on my computer with my project on Android Studio and I have tried several methods described in this thread How do I add a library project to the Android Studio?
No matter what method I use, I keep getting the error stated in the title. Some threads on Stack Overflow suggest that this is due to submodules within the library and that it could be fixed with "git submodule update --init" but that didn't do anything for me.
As I've said, I tried different methods for adding the library but just for reference, the latest method I did was to add the library to the app/libs/ folder and make the following changes in the code:
settings.gradle: include ':app',':libs:AndroidBeaconLibrary'
build.gradle: added compile project(":libs:AndroidBeaconLibrary") to dependancies.
Ok so I've solved the problem. The issue was that it should have been ':app:libs:AndroidBeaconLibrary' instead of ':libs:AndroidBeaconLibrary' in both gradle files.
This fixed the error but a new one came up:
Error:Cannot cast object '23.0.0' with class 'com.android.repository.Revision' to class 'com.android.sdklib.repository.FullRevision'
I fixed this using this answer https://stackoverflow.com/a/33889117/3001845
I added the lines in the build.gradle file of the library itself under 'buildscript'
The section now looks like this:
buildscript {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.github.JakeWharton:sdk-manager-plugin:220bf7a88a7072df3ed16dc8466fb144f2817070'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.0.3'
}
}
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
When using the Crashlytics plugin in intellij I follow these steps.
Click plugin on toolbar.
Select App
Allow crashlytics to update AndroidManifest.xml as well has my first Activity.
Click "Next"
Try to build the App as the plugin instructs.
Then when i try to build i get this:
package com.crashlytics.android does not exist
I look in my dependencies and library and the jar is nowhere to be found.
What am I missing that would cause the library to not be loaded?
I solved this by following the maven instructions here https://crashlytics.com/downloads/maven and then just grabbing the jar from my .m2 and putting it in my libs folder. (This particular project was started as a maven project, then Maven was discarded and it has not yet been migrated to Gradle, so we're kind of in no-man's land). Anyway, I now have the jar.
The following configuration should work for Gradle-based projects:
buildscript {
repositories {
maven { url "http://download.crashlytics.com/maven" }
}
dependencies {
classpath "com.crashlytics.tools.gradle:crashlytics-gradle:1.+"
}
}
apply plugin: "crashlytics"
repositories {
maven { url "http://download.crashlytics.com/maven" }
}
dependencies {
compile "com.crashlytics.android:crashlytics:1.1.+"
}
Taken from https://crashlytics.com/downloads/gradle
After the automated setup from android studio, I was missing this line:
compile 'com.crashlytics.android:crashlytics:1.1.+'