当前位置: 首页 > 知识库问答 >
问题:

无法修复项目,gradle问题

阎承
2023-03-14

在此处输入代码无法修复项目,android studio新手,需要帮助修复gradle我的gradle文件,从eclipse导入项目时发生,导出完成

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}
apply plugin: 'com.android.application'

dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    compile project(':ksoap2-android-assembly-2.5.8-jar-with-dependencies')
}

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

我得到的错误是

Error:Configuration with name 'default' not found.

更改代码\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

 buildscript {
                repositories {
                    jcenter()
                }
                dependencies {
                    classpath 'com.android.tools.build:gradle:1.2.3'
                }
            }
            android {
                compileSdkVersion 23
                buildToolsVersion "23.0.1"

                defaultConfig {
                    applicationId "com.package.name"
                    minSdkVersion 11
                    targetSdkVersion 23
                    versionCode 1
                    versionName "1.0"
                }
                buildTypes {
                    release {
                        minifyEnabled false
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                    }
                }
            }
            apply plugin: 'com.android.application'

            dependencies {
                compile fileTree(include: '*.jar', dir: 'libs')
                compile project(':ksoap2-android-assembly-2.5.8-jar-with-dependencies')
            }

            android {
                compileSdkVersion 23
                buildToolsVersion "23.0.1"

                defaultConfig {
                    applicationId "com.package.name"
                    minSdkVersion 11
                    targetSdkVersion 23
                    versionCode 1
                    versionName "1.0"
                }
                buildTypes {
                    release {
                        minifyEnabled false
                        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                    }
                }

                sourceSets {
                    main {
                        manifest.srcFile 'AndroidManifest.xml'
                        java.srcDirs = ['src']
                        resources.srcDirs = ['src']
                        aidl.srcDirs = ['src']
                        renderscript.srcDirs = ['src']
                        res.srcDirs = ['res']
                        assets.srcDirs = ['assets']
                    }

                    // Move the tests to tests/java, tests/res, etc...
                    instrumentTest.setRoot('tests')

                    // Move the build types to build-types/<type>
                    // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
                    // This moves them out of them default location under src/<type>/... which would
                    // conflict with src/ being used by the main source set.
                    // Adding new build types or product flavors should be accompanied
                    // by a similar customization.
                    debug.setRoot('build-types/debug')
                    release.setRoot('build-types/release')
                }

            }

共有1个答案

柳玄裳
2023-03-14

defaultConfig添加到android块中

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.package.name"
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

编辑1:gradle文件的android部分应该在应用程序构建中。gradle不在项目根目录中gradle

有两份Gradle档案

下面是一个根项目Gradle文件示例

// 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.0.0-alpha1'

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

示例模块Gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.package.name"
        minSdkVersion 11
        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:recyclerview-v7:23.1.1'
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.android.support:cardview-v7:23.1.1'
}
 类似资料:
  • 我使用的是Android studio 1.3.1,无法同步Gradle项目错误: 我默认的和仍然显示这个错误,有人能告诉我为什么我得到这个错误吗?

  • 我无法构建gradle项目,即使我编辑gradle属性,我也会得到以下错误: 我该如何解决这个问题?

  • Gradle同步失败:原因:在C:\Users\android\sdk中找不到哈希字符串为“android-18”的目标。有关详细信息,请查阅IDE日志 每次将项目导入android studio时,我都会发现这个错误。

  • 我是Android Studio的新手。目前,我正在使用Android Studio 4。当导入基于旧版本(项目的Github链接)构建的项目时,gradle同步失败。出现以下错误: Gradle同步失败:无法使用Gradle分发https://services.gradle.org/distributions/gradle-2.10-all.zip运行构建操作。有关更多详细信息,请参阅IDE日志

  • ''处理命令时发生未知的服务器端错误。原始错误:执行adbExec时出错。原始错误:“命令”D:\program\android sdk\platform tools\adb。exe-P 5037-s f8cb3e08安装-g E:\appium\resources\app\node_modules\appium\node_modules\io。阿皮姆。设置\apks\settings\u apk

  • 问题是gradle找不到依赖项的jar,但gradle找错了地方。Gradle一直在错误的目录(谷歌和Android支持libary的目录)中搜索文件.... 在以下位置搜索:文件:/d://programme/androis-sdks/extras/android/m2repository/org/springframework/android/spring-android-rest-templ