Android studio error (17, 0) could not find method maven() - java

Project Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.1.0' // google-services plugin
}
repositories {
google()
}
}
allprojects {
// ...
dependencies {
// ...
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
Module Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '26.0.0'
defaultConfig {
applicationId "com.example.example"
minSdkVersion 19
targetSdkVersion 23
}
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.firebase:firebase-core:11.2.2'
compile project(':rateMyApp')
compile files('libs/android-async-http-1.4.6.jar')
compile files('libs/com-uvxghdmx-ucuwreks167365.jar')
compile files('libs/org.apache.http.legacy.jar')
compile files('libs/universal-image-loader-1.9.3.jar')
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.balysv:material-ripple:1.0.2'
compile 'com.google.android.gms:play-services-ads:11.2.2'
}
apply plugin: 'com.google.gms.google-services'
Getting Error
Error:(17, 0) Could not find method maven() for arguments [build_2rpdxydj6arlyq4m2v87kde3g$_run_closure1$_closure2$_closure3#70ca8e63] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Please Help Me...

You can work this one around like by adding the mavenCentral() to the repositories, then add the code to the repositories below the mavenCentral() line, and then resync:
allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
this should remove the conflict with the sync.

Related

Android Gradle dependencies are not working in new update of Android Studio

I am trying to implement any kind of dependency ,in new android studio IDE which is stable in JDK 11, like payumoney or something else. It syncs successfully but when trying to use it in java file or xml file getting error like can not find symbol that you are using.
In updated Android Studio when we create new project we are getting code in build.gradle file which is given below :
build.gradle :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and build.gradle(app) :
plugins {
id 'com.android.application'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.wipenex.payudemo"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.firebase:firebase-common:20.0.0'
implementation 'com.payumoney.core:payumoney-sdk:7.4.4'
implementation 'com.payumoney.sdkui:plug-n-play:1.6.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
And it looks like :
I was trying to add some code in build.gradle(app) :
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.1'
classpath 'com.google.gms:google-services:4.3.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
but getting error.
I have wrote code before getting exact code or concept behind it after a lot of error handling.
In my system it works when modified in settings.gradle inside of repositories { } :
maven{ url("https://repo.gradle.org/gradle/libs-releases/") }
maven { url "https://jitpack.io" }
The complete settings.gradle file should have as given below :
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven{ url("https://repo.gradle.org/gradle/libs-releases/") }
maven { url "https://jitpack.io" }
}
}
rootProject.name = "PayU Demo"
include ':app'
I hope the above code helpful to you all guys.
It seems, that the dependency can not be loaded from JCenter. PayU mentioned in their [developer guide][1], that implementation("com.payumoney.sdkui:plug-n-play:<version>") is enough.
I recommend to remove the other payumoney dependencies and change your repository scope in the build.gradle to
repositories {
google()
mavenCentral()
maven{ url("https://repo.gradle.org/gradle/libs-releases/") }
maven { url "https://jitpack.io" }
}
``
[1]: https://developer.payumoney.com/android/

cannot resolve symbol gson

I have big troubles using the gson library. When building the project i get:
"Cannot resolve symbol gson"
I have googled for hours but no solution seems to work. Here is my build.gradle file:
android {
compileSdkVersion 24
buildToolsVersion "28.0.2"
defaultConfig {
applicationId "com.example.jasminkrhan.vaktija"
minSdkVersion 24
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.8.2'
}
And also my build.gradle file for the project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
repositories {
maven {
url "http://repo1.maven.org/maven2"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
repositories {
maven {
url "http://repo1.maven.org/maven2"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Does someone see something wrong with my code? Why does not android studio find the library? I have already tried to restart Android Studio but that doesn't help.
compile is outdated. Please use implementation
implementation 'com.google.code.gson:gson:2.8.5'
You need these in Project Level build.gradle
buildscript {
repositories {
google()
jcenter()
}
.....
allprojects {
repositories {
google()
jcenter()
}
}
Try to write the repositories all in one, and use the functions included for Google dependencies and jcenter already, instead of providing the URL. Like so:
buildscript {
...
repositories {
google()
jcenter()
}
}
And also:
allprojects {
repositories {
google()
jcenter()
}
}
It's also important that you start using the implementation tag instead of compile in gradle, as its being deprecated:
implementation 'com.google.code.gson:gson:2.8.5'

Execution failed for task for ':app:transformClassesWithMultidexlistForDebug'

hi when i compile my project the error below shows up
Execution failed for task for ':app:transformClassesWithMultidexlistForDebug'.
java.io.IOException: Can't write [C:\Users\user\app\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\user\.gradle\caches\transforms-1\files-1.1\support-core-ui-25.2.0.aar\8bd3003da78946d664f3d05c69c73bfa\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:android/support/v4/view/ViewPager$2.class]))>
to note i used all the answers from this Thread
+delete .Gradle Folder
+Added multiDexEnabled true
but it didn't work for me
my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "net.amiapp.candiesstory"
minSdkVersion 15
targetSdkVersion 27
multiDexEnabled true
ndk {
moduleName "player_shared"
}
}
sourceSets {
main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] // レガシー ndk-build サポートを無効にする
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dependencies {
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.google.android.gms:play-services-ads:11.8.0'
implementation 'com.google.android.gms:play-services-games:11.8.0'
implementation 'com.google.android.gms:play-services-plus:11.8.0'
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
}
}
here the project.gradle
buildscript {
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
repositories {
mavenCentral()
google()
maven { url "https://maven.google.com" }
jcenter()
maven { url "https://maven.google.com" }
}
}
any help is appreciated , thanks in advance
Remove these lines and delete these jar files
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
Your compileSdk is set to 27, not 19, and NineOldAndroids is a deprecated library for several years
You should also find the proper implementation dependencies for javax.inject and dagger rather than using jars
You can also remove these repos as jcenter includes Maven Central
mavenCentral()
maven { url "https://maven.google.com" }
maven { url "https://maven.google.com" }

Error:(11, 0) Declaring custom 'clean' task when using the standard Gradle lifecycle plugins is not allowed

Hello i am working now on android application with 2 modules the first is my app with buildgradle like
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.alexvasilkov:android-sign-release:0.8.1'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.alexvasilkov.sign'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "dz.condorpos"
minSdkVersion 17
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
storeFile file("foldable-layout-release-key.keystore")
keyAlias "release"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':library')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.github.barteksc:android-pdf-viewer:1.4.0'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.alexvasilkov:android-commons:2.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.afollestad:easyvideoplayer:0.3.0'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.+'
compile 'com.google.firebase:firebase-storage:10.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
the second module is a library included to my project here is the buildgradle(module:library):
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
}
}
// New version can be uploaded with 'gradlew clean :library:jar :library:uploadArchives'
apply from: 'gradle-mvn-push.gradle'
dependencies {
}
the project buildgradle is like :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects { project ->
repositories {
jcenter()
maven { url 'https://dl.bintray.com/drummer-aidan/maven' }
}
// Enabling checkstyle for all sub projects
project == rootProject || project.afterEvaluate {
project.apply plugin: 'checkstyle'
project.extensions.getByName('checkstyle').with {
toolVersion = '6.15'
configFile file("${rootDir}/checkstyle.xml")
}
task checkstyle(type: Checkstyle) {
source 'src'
include '**/*.java', '**/*.xml'
classpath = files()
}
project.tasks.getByName('check').dependsOn 'checkstyle'
project.extensions.getByName('android').with {
lintOptions {
ignore 'GoogleAppIndexingWarning', 'ContentDescription'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
}
the project was working perfectly till yesterday when i added a compile dependencies of picasso in my app module after the gradle sync failed it show this
Error:(11, 0) Declaring custom 'clean' task when using the standard Gradle lifecycle plugins is not allowed.
now even if i remove picasso the error still happening Of course I did not ask the question before long research i found some solutions but didnt work like this
note : an old version of my project still working normal with the same clean task but after some gardle syncs i will get this problem.
I would like to thank you in advance for your assistance
After so many research i found we have to just comment the line of clean task in bulid.gradle(Project) like below :
// task clean(type: Delete) {
// delete rootProject.buildDir
// }][1]

Cannot Import GSON/JSON in Android Studio Using Maven

I'm having a problem importing com.google.gson using Maven. Right now, I'm getting the following errors:
Error:(24, 17) Failed to resolve: junit:junit:4.12
and
Error:(22, 13) Failed to resolve: com.google.code.gson:gson:2.5
Here is the build.gradle for the Project:
buildscript {
repositories {
jcenter()
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
repositories {
jcenter()
mavenCentral()
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and here is the build.gradle for the "Module: App":
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.name.testversion"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.google.code.gson:gson:2.5'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
}
Please tell me what to do to fix these problems and successfully import "com.google.code.gson:gson:2.5" into Android Studio to use with this project.
Also, just so you know, I'm newer to Android Studio, just to put that into perspective, and this is my first time using Maven in Android Studio, but not first time using Maven in general.
Change your project gradle to this one
//Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
On your Project build.grade try using:
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
Instead of just repositories {...}

Categories