Andriod Gradle问题

时间:2020-01-27 02:56:29

标签: android android-studio gradle

我在Andriod studio(最新的andriod Studio版本)中导入了一个应用程序,然后尝试了所有类似的操作:再次卸载并安装JDK,为每个库重新应用,更新SDK管理器,代码在5-6之前年前,所以现在我正在尝试更新Gradle,而我无法解决此问题。

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()
        }
    }

错误

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

2 个答案:

答案 0 :(得分:1)

更新

在顶级gradle文件中添加类似的google maven回购

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }       
        google()
    }
}

  1. 构建
  2. 清洁项目

然后

  1. 打开android studio
  2. 点击文件(在顶部栏中)
  3. 使缓存无效并重新启动
  4. 再次使缓存无效并重新启动

尝试一下(您错过了应用级gradle文件中的许多内容)

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
}
}

您的实现文件(库)可能已过期,请尝试对其进行更新或使用maven仓库而不是jar文件

答案 1 :(得分:0)

右键单击您的项目,单击“打开模块设置”,然后在左侧的段中单击“项目”。它应该给你一些下拉菜单“ Android Gradle Plugin Version”和“ Gradle Version”。确保前者处于应有的3.5.1,或更改它直到它(或更高版本)。您也可以更改第二个(“ Gradle版本”),但我不知道该怎么做。我的是5.4.1。