Android Strudio 常見錯誤以及解決辦法

錯誤一

Error:(19, 0) Gradle DSL method not found: 'android()'
Possible causes:<ul><li>The project 'Zhihu-Parallax-Animation-develop' may be using a version of Gradle that does not contain the method.
<a href="open.wrapper.file">Open Gradle wrapper file</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

解決

build.gradle:
buildscript {
    repositories {
        mavenCentral()
        maven { url "http://dl.bintray.com/populov/maven" }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
    }
}

allprojects {
    repositories {
        mavenCentral()
        maven { url "http://dl.bintray.com/populov/maven" }
    }
}

app/build.gradle:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.3'

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName '1.0'
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:23.2.1'
}

Then run gradle:
gradle installDebug

錯誤二

Error:(16, 0) Gradle DSL method not found: 'runProguard()'
Possible causes:

The project 'GridViewPager' may be using a version of Gradle that does not contain the method.Gradle settings

The build file may be missing a Gradle plugin.Apply Gradle plugin

解決

Before upgrade build tools version:
dependencies {
        classpath 'com.android.tools.build:gradle:0.12.0'
    }

After upgrade build tools version:
dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }


Previous code :buildTypes {        
    release {            
          runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
Current code :buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

參考:http://stackoverflow.com/questions/27016385/error26-0-gradle-dsl-method-not-found-runproguard

錯誤三

Error:Configuration with name 'default' not found.

解決

http://stackoverflow.com/questions/22743582/error-configuration-with-name-default-not-found-in-android-studio

錯誤四

Error:(59) No resource identifier found for attribute 'strokeWidth' in package 'org.hybridsquad.droidlab'

解決

因爲沒有引入viewpagerindicator (把compile project(':library') 刪除後,需要各種引用,否則會因爲找不到某個類而報錯)
http://www.tuicool.com/articles/ZrInyyI

錯誤五

Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Android\AS_sdk\build-tools\23.0.3\aapt.exe'' finished with non-zero exit value 1

解決

因爲引用了重複的jar包,刪除多餘的jar包

錯誤六

Error:Gradle version 2.10 is required. Current version is 2.8. If using the gradle wrapper, try editing the distributionUrl in D:\ll_s\github\lunbotu\Banner-master\gradle\wrapper\gradle-wrapper.properties to gradle-2.10-all.zip
<a href="fixGradleVersionInWrapper">Fix Gradle wrapper and re-import project</a><br><a href="openGradleSettings">Gradle settings</a>

解決

在gradle下找到gradle-wrapper.properties,將下面的改爲正確的就好
distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip

錯誤七

Error:找不到引用的jar包資源  

解決

原因有二:
1.jar包版本低了,需要引入高版本的
2.資源找不到了

錯誤八

Error:Could not find com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0.
Searched in the following locations:
    file:/C:/Android/AndroidStudio/AS/gradle/m2repository/com/jfrog/bintray/gradle/gradle-bintray-plugin/1.0/gradle-bintray-plugin-1.0.pom
    file:/C:/Android/AndroidStudio/AS/gradle/m2repository/com/jfrog/bintray/gradle/gradle-bintray-plugin/1.0/gradle-bintray-plugin-1.0.jar
    https://repo1.maven.org/maven2/com/jfrog/bintray/gradle/gradle-bintray-plugin/1.0/gradle-bintray-plugin-1.0.pom
    https://repo1.maven.org/maven2/com/jfrog/bintray/gradle/gradle-bintray-plugin/1.0/gradle-bintray-plugin-1.0.jar
    http://dl.bintray.com/populov/maven/com/jfrog/bintray/gradle/gradle-bintray-plugin/1.0/gradle-bintray-plugin-1.0.pom
    http://dl.bintray.com/populov/maven/com/jfrog/bintray/gradle/gradle-bintray-plugin/1.0/gradle-bintray-plugin-1.0.jar
Required by:
    :Codecafe:unspecified

解決

在build.gradle文件中
dependencies{
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
}

上面那行classpath......與修改的
repositories{//此repositories來自buildscript{}和allprojects{}
    mavenCentral()
    maven { url "http://dl.bintray.com/populov/maven" }
}

可能有衝突,原本修改之前是 
repositories{
 jcenter()
}

錯誤九

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> When running gradle with java 5, 6 or 7, you must set the path to jdk8, either with property retrolambda.jdk or environment variable JAVA8_HOME

解決

1.需要jdk1.8
2.然後進AS->Project Structure->更改JDK location(這個好多人都容易忘記)

錯誤十

Error:(27, 0) Gradle DSL method not found: 'apt()'
Possible causes:<ul><li>The project 'ViewPagerTab' may be using a version of Gradle that does not contain the method.
<a href="open.wrapper.file">Open Gradle wrapper file</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

解決

在引用Butter Knife的時候,沒有在module 的build.gradle文件的頂部添加apply plugin: 'com.neenbedankt.android-apt'(ps:在引用Butter Knife的時候一共需要添加四行代碼)

來源:http://stackoverflow.com/questions/36876158/gradle-dsl-method-not-found-apt

錯誤十一

Error:Cause: null value in entry: UMENG_APPKEY=null

解決

自己應該申請一個友盟的UMENG_APPKEY還有value應該就可以了

很多錯誤信息的解決方法都來自Stack Overflow

解決
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章