我正在尝试使用来自 https://github.com/bright/slf4android 的 slf4android 依赖项但是 gradle sync 有问题。
Build.gardle(项目)
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.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
}
Build.gardle(应用程序)
apply plugin: 'com.android.application'<p></p>
<p>android {
compileSdkVersion 23
buildToolsVersion "24.0.0 rc2"</p>
<pre><code>defaultConfig {
applicationId "com.example.vinod.myapplication"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
</code></pre>
<p>}
buildscript {
repositories {
maven { url "<a href="http://jitpack.io" rel="noreferrer noopener nofollow">http://jitpack.io</a>" }
}
dependencies {
compile('com.gitghub.bright:slf4android:0.1.0'){
transitive = true
}
}
}</p>
<p>dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile('com.gitghub.bright:slf4android:0.1.0'){
transitive = true
}
}</p>
<p></p>
我收到的错误:
Error:(26, 0) Gradle DSL method not found: 'compile()'
Possible causes:<li>The project 'My Application' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>
我是 android 编码的新手,不知道我错过了什么。请帮忙。
最佳答案
url“http://jitpack.io”应该进入项目级 build.gradle 而不是模块级。
将项目级构建 gradle 的 allProjects 更改为此:
allprojects {
repositories {
jcenter()
maven {url "https://jitpack.io"}
}
}
然后从 app build.gradle 中删除 jitpack url 并同步你的项目。
关于未找到 Android Studio Gradle DSL 方法 : compile() while adding slf4android dependency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36671560/