gpt4 book ai didi

android - Android Studio build.gradle 文件报错 Can't apply main & dependencies

转载 作者:行者123 更新时间:2023-11-29 15:55:34 25 4
gpt4 key购买 nike

在将 Eclipse 项目转换为 Android Studio 项目后,build.gradle 中的 Android Studio 出现问题.

我花了2个多小时寻找解决方案,没有结果!!

build.gradle代码:

apply plugin: 'android'

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}

android {
compileSdkVersion 19
buildToolsVersion "17.0.0"

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, 0) 未找到 ID 为“com.android.application”的插件。

屏幕截图

enter image description here

任何帮助将不胜感激......

最佳答案

这个错误信息意味着它根本找不到插件。在 Gradle 中,你需要告诉它去哪里寻找插件,这不同于告诉它去哪里解决模块依赖。将此 block 添加到构建文件的开头:

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

在 Android Studio 创建的项目中,New Project 向导会将其放入项目的顶级构建文件中,但根据屏幕截图,您的项目似乎只有一个构建文件,因此只有一个位置把它。

关于android - Android Studio build.gradle 文件报错 Can't apply main & dependencies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28278545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com