构建失败,出现异常 Android Studio 0.4.3 和 0.4.4 [英] Getting Build failed with an Exception Android Studio 0.4.3 and 0.4.4

查看:23
本文介绍了构建失败,出现异常 Android Studio 0.4.3 和 0.4.4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题:

自从我每次尝试创建一个新项目时都将 Android Studio 更新到 .4.3 时,我会遇到一些构建失败,因此每个新项目都会发生这种情况,那里没有我自己的代码......

since I have updated Android Studio to .4.3 everytime I try to make a new project I get some Build failure, the thing happens with each and every new project, no code of my own there...

我们来看看:

安卓代码:

package com.appgcm;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment())
                .commit();
    }
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        return rootView;
    }
}

}

Build.gradle

Build.gradle

apply plugin: 'android'

android {
compileSdkVersion 19
buildToolsVersion "17.0.0"

defaultConfig {
    minSdkVersion 7
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard rules.txt'
    }
}
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}

Gradle 控制台错误:

Gradle console error:

Executing tasks: [:appgcm:generateDebugSources]

Relying on packaging to define the extension of the main artifact has been deprecated     and is scheduled to be removed in Gradle 2.0
:appgcm:preBuild FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':appgcm:preBuild'.
> Build Tools Revision 19.0.0+ is required.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option     to get more log output.

BUILD FAILED

Total time: 3.265 secs

好吧,我认为这些信息足以拿出一些东西,我仍然不是 gradle 的真正专家,所以你的解释越详细越好.

Ok, I think that is enough information to take something out, I'm still not really expert with gradle, so the detailed your explanations the better.

非常感谢!

我听取了 pyus13 的建议,现在我遇到了另一种错误,这里是:

I took advice from pyus13 and now i'm gatting another sort of error, here it is:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\pandolet\workspace\APPGCM\appgcm\build.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':appgcm'.
> Plugin with id 'android' not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 0.306 secs

根级 build.gradle:

Root level build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        'com.android.tools.build:gradle:0.8.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

推荐答案

首先使用您的 Android SDK 管理器下载最新的 Build Tools 19.0.0 和 19.0.1.

First download latest Build Tools 19.0.0 and 19.0.1 using your Android SDK Manager.

然后将 buildToolsVersion "17.0.0" 更改为在您的 build.gradle 文件中

Then do change buildToolsVersion "17.0.0" in to indside your build.gradle file

buildToolsVersion "19.0.0"

因为在发布文档中提到 Gradle 1.10 和 android 插件 0.8 需要 buildTools 19.0.0+

Because as mentioned in release documents Gradle 1.10 and android plugin 0.8 requires buildTools 19.0.0+

还要确保您的根项目级别 build.gradle 文件具有 gradle 插件 0.8 作为类路径

Also make sure your root project level build.gradle file has gradle plugin 0.8 as classpath like this

    classpath 'com.android.tools.build:gradle:0.8.+'

这篇关于构建失败,出现异常 Android Studio 0.4.3 和 0.4.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆