java - “java”插件与 Android 插件不兼容

标签 java android android-studio android-gradle-plugin

我在安装 Android Studio 并创建了一个简单的应用程序后立即收到错误消息。

遵循的步骤:

  1. 全新下载并安装 Android Studio。
  2. 创建了一个新项目。

当项目加载时,gradle 失败并出现错误:

Error:The 'java' plugin has been applied, but it is not compatible with the Android plugins.

模块 Gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "info.ankitjc.happybirthday"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    testCompile 'junit:junit:4.12'
}

项目 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.2.3'

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

我在这里搜索了可能的解决方案。

文件后 > 使缓存无效/重新启动 After File > Invalidate Cache/Restart

最佳答案

我认为路径还没有设置为环境变量。

检查您是否声明了 java sdk 路径。将路径设置为环境变量。

在 cmd 中输入“javac”(cmd 必须有管理员权限)。

如果编译不成功

1 。打开jdk位置,复制“bin”的路径

2。在控制面板中打开系统属性。

3。高级系统设置->然后选择“环境变量”

4。点击“新建”

5。设置变量名为“路径”,变量值复制地址

然后再试一次

关于java - “java”插件与 Android 插件不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41642538/

相关文章:

java - 如何在我的代码中使用 BigInteger 来计算素数?

java - 如何使用 Unicode 或 Java 中的任何替代方法显示 "sigma-hat"? (我有部分解决方案)

android - EditText 中双值的双向数据绑定(bind)

android - Android Studio 中编辑器折叠和区域注释的区别

java - 我想检测滚动事件的结束

java - 将<error-page>添加到不带web.xml的特定servlet

java - Spring Boot + JAX-WS 无需额外的 servlet?

java - 如何访问 JSONObject、JSONObject 和 JSONArray 中的内容? Java/安卓

android - 如何编写 fql 查询以列出特定位置的 friend

android - Activity 未在 list 中注册 Lint 警告