安卓编译错误;已应用Java插件,与android不兼容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26861011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 03:24:52  来源:igfitidea点击:

Android compile error; Java plugin has been applied, not compatible with android

javaandroidgradlewear-os

提问by Riekelt

So I've made a wearable application where I can control a robot-car with the buttons on screen with the MessageListenerService. After trying to build the project, I had some problems where it asked me to install "Android Support Repository" from the SDK, which I already had. I found another similar problem on SO (link)which had a sort-of solution, but now it says

所以我制作了一个可穿戴应用程序,我可以在其中使用 MessageListenerService 使用屏幕上的按钮控制机器人汽车。在尝试构建项目后,我遇到了一些问题,它要求我从我已经拥有的 SDK 安装“Android 支持存储库”。我在 SO (link) 上发现了另一个类似的问题,它有一个解决方案,但现在它说

"Error: The java Plugin has been applied, but it is not compatible with the Android Plugins"

“错误:Java 插件已应用,但与 Android 插件不兼容”

This is my build.gradle in my wearable module

这是我的可穿戴模块中的 build.gradle

apply plugin: 'com.android.application'
apply plugin: 'java'


sourceCompatibility = JavaVersion.VERSION_1_6   //these two lines
targetCompatibility = JavaVersion.VERSION_1_6   //are the only ones that matter

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }
signingConfigs {
    release {
        keyAlias 'C:\Users\Riekelt\coolie.jks'
        keyPassword 'cut-out'
        storeFile file('path/to/release.keystore')
        storePassword 'cut-out'
    }
}

defaultConfig {
    applicationId "robowheel.robond"
    minSdkVersion 20
    targetSdkVersion 20
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release

    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:+'
compile "com.android.support:support-v4:20.0.+"
compile 'com.google.android.gms:play-services-wearable:+'
 //   compile 'com.google.android.gms:play-services-wearable:6.1.11'

}

Anyone know what is the matter? Thanks in advancoi

有谁知道是怎么回事吗?提前致谢

采纳答案by Nilzor

The problem is that you cannot apply both the com.android.applicationand the javaplugin in the same module. Why are you doing that? There's nothing in the question you reference that tell you to apply the java plugin.

问题是您不能在同一个模块中同时应用com.android.applicationjava插件。你为什么这样做?您引用的问题中没有任何内容告诉您应用 java 插件。

Remove the line with apply plugin: 'java', and you're good to go

删除带有 的行apply plugin: 'java',您就可以开始了

回答by Mavamaarten

For those that are using kotlin and are making an Android library: make sure to use apply plugin: 'kotlin-android'instead of apply plugin: 'kotlin'.

对于那些使用科特林并正在使用Android库:一定要使用apply plugin: 'kotlin-android'代替apply plugin: 'kotlin'

回答by nvbach91

For those who are using corporate/company custom gradle repo, remove or fix the init.gradlefile from your gradle home. Location on Windows is C:\Users\User\.gradle\init.gradle. That's where all the nasty things happen.

对于那些使用企业/公司自定义 gradle 存储库的人,请init.gradle从您的 gradle 主页中删除或修复该文件。Windows 上的位置是C:\Users\User\.gradle\init.gradle. 这就是所有讨厌的事情发生的地方。