I have an android projct in Android Studio, was all previously working the last time I used it, however, I've upgraded Android Studio and now I am getting a weird problem.
In the error output in Android Studio I have the following:
Warning: Project MyApp: provided dependencies can only be jars. com.google.android.gms:play-services.6.5.87 is an Android Library
Warning: Project MyApp: provided dependencies can only be jars. com.MyCompany.MyLibrary:aar:1.0 is an Android Library.
Below is my build.gradle file.
apply plugin: 'android'
android {
compileSdkVersion 21
buildToolsVersion "20.0.0"
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
defaultConfig {
//applicationId "com.MyCompany.MyApp"
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
debuggable false
}
}
repositories {
mavenLocal()
}
}
dependencies {
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:support-v4:21.0.0'
compile 'com.MyCompany:CritiMon:1.0'
compile 'com.MyCompany:Library:1.1'
provided 'com.MyCompany:MyLibrary:1.0'
compile 'com.MyCompany:NavigationDrawerManager:2.1'
provided 'com.google.android.gms:play-services:+'
compile files('libs/ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar')
}
Your provided dependencies can only be jars, your custom Android Libraries in your project should be compile at build time.
Change this:
provided 'com.MyCompany:MyLibrary:1.0'
provided 'com.google.android.gms:play-services:+'
to
compile 'com.MyCompany:MyLibrary:1.0'
compile 'com.google.android.gms:play-services:+'
I restore the Android Plugin Version from 1.1.0 to 1.0.0 and it work.
You can do it by the order:
Right-click your project.
Select `Open Module Settings`
Select `Project`
Change the `Android Plugin Version`
Related
Hey guys recently I was reading an answer and I came across this
Add the following dependency to your app's Gradle file and run the application.
debugCompile 'com.amitshekhar.android:debug-db:1.0.0'
My question is this where do I paste this to?
I copied This to the build.gradle file in the android studio and I got a lot of errors saying
Error:(9, 0) Gradle DSL method not found: 'debugCompile()' Possible causes:<ul><li>The project 'DB' may be using a version of the
Android Gradle plug-in that does not contain the method (e.g.
'testCompile' was added in 1.1.0). Upgrade
plugin to version 2.3.3 and sync projectThe project 'DB'
may be using a version of Gradle that does not contain the method. Open Gradle wrapper fileThe
build file may be missing a Gradle plugin. Apply Gradle plugin
Any Pointers on how to add a dependency would be appreciated! PS The official documentation just confuses me even more so please keep the answer simple Thanks :)
You need to add the dependency inside the dependencies block in your module build.gradle not in your project build.gradle.
You can see the sample how adding the dependency from UniversalMusicPlayer sample. Here the sample of module build.gradle without the license:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.android.uamp"
minSdkVersion 17
targetSdkVersion 26
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
abortOnError true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
provided 'com.google.android.wearable:wearable:2.0.3'
compile 'com.google.android.gms:play-services-cast-framework:11.0.1'
compile 'com.google.android.support:wearable:2.0.3'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:mediarouter-v7:26.1.0'
compile 'com.android.support:leanback-v17:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.google.android.exoplayer:exoplayer:r2.5.0'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:26.1.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
}
Take a look at the dependencies block:
dependencies {
...
}
You need to add debugCompile 'com.amitshekhar.android:debug-db:1.0.0'
there. So it will become:
dependencies {
...
debugCompile 'com.amitshekhar.android:debug-db:1.0.0
}
I have a problem with android studio.
I have added the .jar file of okhttp from this link : https://github.com/square/okhttp to my libs directory on my android studio. and when I try to add this line : compile 'com.squareup.okhttp3:okhttp:3.2.0' in the dependencies in build.gradle(Module:app), after trying to syncing it I get error 28, 13. Actually after researching I found out that I can't compile anything in dependencies and sync it remember that I have checked my "android SDK build tool" is installed.
hear is the whole of my code in build.gradle(app) directory:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.kasra.stormy"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'], )
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile files('libs/okhttp-3.2.0.jar')
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
I'll be very glad and thankful if someone help me fix this problem.
Thank you very much:)
Either your internet is bad and you can't download that file from JCenter, or you are just missing a repositories section in your gradle file.
apply plugin: 'com.android.application'
repositories {
jcenter()
}
Also, if you are going to be compiling using gradle instead of a JAR file, then delete the file libs/okhttp-3.2.0.jar and remove the line that says compile files('libs/okhttp-3.2.0.jar').
It is also worth mentioning that you don't need any lines that start with compile files('libs/ because compile fileTree(dir: 'libs', include: ['*.jar'], ) already includes all JAR files within the libs/ folder.
It may help someone. In my case after update com.squareup.okhttp3 to the latest version, I got this error in Android Java libaray. Then I update the Java version to 1.8 which solved my problem.
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
you should change the build.gradle(app):
use
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
instead of
compile 'com.squareup.okhttp3:okhttp:3.2.0'
or just follow the guide as mentioned here.
Just Replace the dependencies with folowng dependencies and they will work for sure.(100%).
if in future this issue comes again then go to https://square.github.io/okhttp/ and update your dependencies with latest one
//define any required ok http without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
//define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
Just remove compile files('libs/okhttp-3.2.0.jar')
I solved my problem by editing my build.gradle as below:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion 21
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.txt'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile project(':library')
//compile('com.squareup.okhttp3:okhttp:+') {
// exclude group: 'org.json'
//}
//replaced as below:
compile 'com.squareup.okhttp3:okhttp:3.9.1'
}
Check your code in app.gradle
apply plugin: 'com.android.application'
repositories {
jcenter()}
OR
make your compile okhttp to offline mode, next you uncheck offline mode in setting -> gradle. and try it again
You will not need this
compile 'com.squareup.okhttp3:okhttp:3.2.0'
rather you will need
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
As of today the 30th of September 2020
Check https://square.github.io/okhttp/ for documentation
I've just ported a legacy codebase from Eclipse/ADT to Android Studio. Process went quite fine, app is compiling and running without errors.
Now I'm trying to add Google Play Services (in order to use Analytics) to the app. I'm following the guide https://developers.google.com/analytics/devguides/collection/android/v4/ and I've added the compile instruction in build.gradle.
When I add the file google-services.json and try to compile, I receive an error related to the intermediate build generation for AppCompat and Material Design.
This is the error I receive then I do a gradle clean:
http://pastebin.com/GG7Pu7iu
This is my app's build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "23"
defaultConfig {
applicationId "com.mediana.myapp"
minSdkVersion 16
targetSdkVersion 19
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
debug {
minifyEnabled false
}
}
packagingOptions {
exclude 'META-INF/NOTICE.txt' // will not include NOTICE file
exclude 'META-INF/LICENSE.txt' // will not include LICENSE file
}
}
dependencies {
compile files('libs/commons-codec-1.7.jar')
compile files('libs/commons-io-2.4.jar')
compile files('libs/crittercism_v4_1_0.jar')
compile files('libs/svgAndroid2-src.3Jan2014.jar')
compile files('libs/gcm.jar')
compile files('libs/gson-2.2.4.jar')
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.android.support:gridlayout-v7:19.+'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.google.android.gms:play-services-ads:8.1.0'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'
}
apply plugin: 'com.google.gms.google-services'
I'll provide anything you need
Thanks in advance
I'm trying to use some libraries into my android project and I'm facing some problems with different libraries. I have a library which I import from maven repository that has "nineoldandroids" library dependency. After that I have another import that uses the same library and I did a exclude of that module. Now if I sync Gradle everything works fine but when I try to run my app I get the following error
"Error:Class com.nineoldandroids.animation.Animator.AnimatorListener has already been added to output. Please remove duplicate copies."
I think that both libraries are trying to use the same Listener and I get that error but I'm not able to solve it and I didn't find useful information for me. If somebody can help me I would appreciate it. This is my gradle file. BTW last library must be manually included and it's placed in my "libs" folder.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.infortec.acostela.pescamerca"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories{
jcenter()
flatDir {
dirs 'libs'
}
}
dexOptions {
preDexLibraries = false
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.+'
compile "com.android.support:gridlayout-v7:18.0.+"
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'commons-net:commons-net:3.3'
compile 'net.sf.opencsv:opencsv:2.3'
compile 'com.rengwuxian.materialedittext:library:1.8.2'
compile ('libs.example:material:0.4.3#aar'){
exclude module: 'nineoldandroids'
}
}
Finally I solved it.
The problem was that I must exclude the whole library, not only the module so writing the following solved it.
compile ('com.rengwuxian.materialedittext:library:1.8.2'){
exclude group: 'com.nineoldandroids', module: 'library'
}
I tried to add smoothprogressbar library to my android project
I added these lines to my build.gradle
dependencies {
// of course, do not write x.x.x but the version number
compile 'com.github.castorflex.smoothprogressbar:library:0.5.2'
}
And when i sync the gradle its saying that
Failed to find : com.github.castorflex.smoothprogressbar:library:0.5.1
I tried putting mavenCentral() and maven url in build.gradle and other solutions which i found in stackoverflow but nothing seems to work.
Edited :
This is my full gradle file
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'com.android.support:cardview-v7:21.+'
compile('com.google.http-client:google-http-client-android:1.18.0-rc') {
exclude(group: 'com.google.android', module: 'android')
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
}
// You must install or update the Support Repository through the SDK manager to use this dependency.
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile project(path: ':backend', configuration: 'android-endpoints')
// You must install or update the Support Repository through the SDK manager to use this dependency.
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile project(':library')
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:4.4.52'
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:support-v13:19.+'
compile 'com.google.code.gson:gson:2.+'
compile 'com.github.castorflex.smoothprogressbar:library:0.5.2'
}
android {
signingConfigs {
...
}
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
applicationId ...
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
dexOptions {
preDexLibraries = false
}
productFlavors {
}
}
Works for me. You should post more of your build.gradle script (in particular, how exactly you tried to put mavenCentral() in the script), but the gist is that you need the following outside of the android {} block in the script (and this is in addition to the similar code in the buildscript {} block):
buildscript {
// ...
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.github.castorflex.smoothprogressbar:library:0.5.2'
}
android {
// ...
}
Then re-sync your project with Gradle.
Use this approach:
compile 'com.github.castorflex.smoothprogressbar:library:0.5.2#aar'