50

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

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

This is my build.gradle in my wearable module

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

Community
  • 1
  • 1
Riekelt
  • 713
  • 2
  • 6
  • 14

3 Answers3

65

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'.

Mavamaarten
  • 1,959
  • 18
  • 19
44

The problem is that you cannot apply both the com.android.application and the java plugin 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.

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

Nilzor
  • 18,082
  • 22
  • 100
  • 167
  • That's it. Thanks! I was following a guide to fix 1 problem, so maybe that was it? Anyway, fixed it and now I am back at my original problem... – Riekelt Nov 11 '14 at 16:18
  • As for your original problem, might this answer help? http://stackoverflow.com/questions/23590746/how-to-set-global-repositories-for-gradle-that-i-can-use-them-in-each-gradle-pro – Nilzor Nov 11 '14 at 16:26
  • Unfortunately not, but I'll play with it a bit later. Thanks again – Riekelt Nov 16 '14 at 19:12
  • Just wanted to add that this problem can also be cause by having `apply plugin: 'application'` in your code. And removing that line will also fix the problem. Well atleast it did for me – smac89 Jan 18 '15 at 20:42
  • 15
    Android Studio says to `apply plugin: 'java'` for JUnit4! – IgorGanapolsky Apr 06 '15 at 20:20
  • 4
    Nizor, what if we want to use checkstyle, findbugs; and we need to apply java plugin. Is there any other way? – vishal sahasrabuddhe Aug 06 '15 at 16:51
  • 5
    For **apply plugin: 'groovy'** also message remain same _Error:The 'java' plugin has been applied, but it is not compatible with the Android plugins._ – CoDe Aug 26 '16 at 05:41
2

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

nvbach91
  • 166
  • 8