安卓工作室升级至0.8.5版本导致Gradle错误

3

在升级到Android Studio 0.8.5之前,我的Gradle一直在工作。现在,gradle构建出现了错误消息:

错误:依靠打包来定义主要工件的扩展名已被弃用,并计划在Gradle 2.0中删除(类java.lang.String)

我附上build.gradle文件供参考:

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://saturday06.github.io/gradle-android-scala-plugin/repository/snapshot' }
        flatDir {
            dirs 'libs/'
        }
//        flatDir {
//            dirs '/Users/sto/workspace/robolectric-gradle-plugin.sonny/build/libs/'
//        }
//        flatDir {
//            dirs '/Users/sto/workspace/gradle-android-scala-plugin/build/libs/'
//        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
        classpath 'jp.leafytree.gradle:gradle-android-scala-plugin:1.0-SNAPSHOT'
        classpath 'org.robolectric:robolectric-gradle-plugin.sonny:0.12.1'
        classpath "commons-io:commons-io:2.4"
        classpath 'net.lingala.zip4j:zip4j:1.3.2'
    }
}

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs/'
    }
}


apply plugin: 'com.android.application'
apply plugin: 'android-scala'
apply plugin: 'robolectric'

robolectric {
    include '**/*Test*.class'
}

android {
    compileSdkVersion 19
    buildToolsVersion '20.0.0'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName '1.0'
//        testInstrumentationRunner "android.test.InstrumentationTestRunner"
        testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }
    packagingOptions {
        exclude 'rootdoc.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'decoder.properties'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'LICENSE.txt'
    }

    sourceSets {
        main {
            java.srcDirs = ['src/main/gen-java', 'src/main/java', 'src/main/scala']
        }
        androidTest.setRoot('src/androidTest/')
        androidTest {
            java.srcDirs = ['src/androidTest/scala', 'src/androidTest/java']
        }
    }

    android {
        lintOptions {
            abortOnError false
        }
    }

    buildTypes {
        debug {
            runProguard true
            proguardFile file('proguard-rules-debug.txt')
        }
        release {
            runProguard true
            proguardFile file('proguard-rules.txt')
        }
    }
}

dependencies {
    compile project(':swiper')
    compile 'org.scala-lang:scala-library:2.11.2'
    compile 'org.json4s:json4s-native_2.11:3.2.10'
    compile 'com.google.android.gms:play-services:4.0.30'
    compile 'com.google.android:android:4.1.1.4'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.2'
    compile 'com.loopj.android:android-async-http:1.4.4'
    compile 'com.edmodo:cropper:1.0.1'
    compile 'de.hdodenhof:circleimageview:1.1.1'
    compile 'org.fusesource.mqtt-client:mqtt-client:1.10'
    compile 'log4j:log4j:1.2.17'
    compile 'de.mindpipe.android:android-logging-log4j:1.0.3'
    compile('org.apache.thrift:libthrift:0.9.1') {
        transitive = false
    }
    compile 'ch.hsr:geohash:1.0.10'
    compile 'org.slf4j:slf4j-android:1.7.7'

    androidTestCompile('junit:junit:4.11') {
//        exclude module: 'hamcrest-core'
    }
    androidTestCompile('org.robolectric:robolectric:2.3') {
        exclude module: 'classworlds'
        exclude module: 'commons-logging'
        exclude module: 'httpclient'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'plexus-container-default'
        exclude module: 'plexus-interpolation'
        exclude module: 'plexus-utils'
        exclude module: 'wagon-file'
        exclude module: 'wagon-http-lightweight'
        exclude module: 'wagon-provider-api'
    }

}

我仍然可以使用命令行构建(gradle版本为1.12),但没有使用Studio,我无法设置我的常规断点进行调试。

1个回答

2

更新:

事实证明,导致我(也很可能是您,考虑到上面的构建文件)遇到此问题的原因是Scala插件。 Scala插件存在一个错误,防止Android Studio导入Gradle项目。该问题的解决方案已经推出,因此为了使Android Studio重新工作,您可以禁用Scala插件或更新它。

  1. 打开设置/首选项
  2. 打开左侧的插件部分
  3. 找到Scala插件
  4. 右键单击插件并单击重新加载插件列表
  5. 再次右键单击插件并单击更新插件

这使我能够在Android Studio中进行Gradle同步和构建,希望对您有所帮助!

原始答案如下:

看起来这是Android Studio的一个错误。希望很快就会修复。

与此同时,您可以通过将调试器附加到应用程序的运行进程来调试应用程序,而不是从Android Studio启动应用程序。您可以通过两种方式完成此操作。

  • 通过菜单:运行 -> 附加调试器到Android进程
  • 按下播放/构建按钮右侧的第二个按钮。它看起来像一个带有绿色小虫子的灰色电话/矩形

这样做后,会显示一个对话框,列出可用于调试的应用程序。选择您的应用程序,然后按确定。现在应该可以使用断点。

如果您需要调试发生在应用程序启动时的内容,则可以使用以下步骤告诉Android在启动某些应用程序时等待调试器:

  1. 在手机上打开Android设置
  2. 打开开发人员选项
  3. 确保选中了等待调试器
  4. 选择调试应用并选择您的应用程序

然后,当您启动应用程序时,它将等待您通过上述两种方法之一附加调试器。

希望这可以帮助您!


谢谢,Scala插件更新解决了这个问题! - ShayakB

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接