问题
I imported an application in Andriod studio(the newest andriod studio version), and I tried everything like: uninstall and install the JDK again, re-apply for each library, updating the SDK manager, the code is before 5-6 years ago, so now im trying to update the Gradle and I couldn't fix this issue.
build.gradle(modules:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 16
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.App"
minSdkVersion 11
targetSdkVersion 29
}compile
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
compileSdkVersion = 29
}
dependencies {
implementation files('libs/asmack-issue-13.jar')
implementation files('libs/gcm.jar')
implementation files('libs/gson-1.7.1.jar')
implementation files('libs/httpmime-4.1-beta1.jar')
implementation files('libs/mediationsdk-6.4.17.jar')
implementation files('libs/PayPalAndroidSDK.jar')
}
Gradle-wrapper.propertis
#Mon Jan 27 05:34:23 GST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Project Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
The error
Total time: 12.797 secs
ERROR: Gradle DSL method not found: 'google()'
Possible causes:
The project 'App_copy' 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 3.5.1 and sync project
The project 'App_copy' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file
The build file may be missing a Gradle plugin.
Apply Gradle plugin
回答1:
Right click on your project, click "Open Module Settings", then click "Project" in the segment on the left. It should give you some dropdowns "Android Gradle Plugin Version" and "Gradle Version". Make sure the former is at 3.5.1 like it should be, or change it until it is (or is a higher version). You COULD also change the second one ("Gradle Version"), but I don't know what to. Mine is at 5.4.1.
回答2:
Update
Add google maven repo like that in top level gradle file
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
google()
}
}
and
- Build
- clean project
then
- Open android studio
- Click file (in the top bar)
- Invalidate caches and restart
- again Invalidate caches and restart
Try this (You missed many things in your app level gradle file)
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.App"
minSdkVersion 11
targetSdkVersion 29
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
And your implementation files(libraries) may be out dated, please try to update it or use maven repo instead of jar file
来源:https://stackoverflow.com/questions/59924712/andriod-gradle-issue