微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法使用gradle构建android项目

我在使用Gradle构建一个简单的android项目时遇到了麻烦.我的构建文件如下:

buildscript {
    repositories {
      mavenCentral()
      // To use a development snapshot version of the plugin, add the
      // Sonatype Snapshots repository.
      maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
      }
    }

    dependencies {
      classpath 'org.gradle.api.plugins:gradle-android-plugin:1.2.1'
    }
  }

  apply plugin: 'android'

  repositories {
      mavenCentral()
  }

  // Sets the package version
  version = "1.0.0"



  // Signing configuration, valid for all builds (1)
  androidSignAndalign {
    keyStore = "path/to/my/keystore"
    keyAlias = "my-key-alias"
    keyStorePassword = "mystorepass"
    keyAliasPassword = "myaliaspass"
  }

  // Configure the filtering of resources with properties from the Gradle's project scope (2)
  processResources {
    expand (project.properties)
  }

  // Configure a dedicated debug build (3)
  task configureDebug << {
    jar.classifier = "debug"
  }

  // Configure a dedicated release build (4)
  task configureRelease << {
    proguard.enabled = true
  }

我得到的错误是这样的:

  11:08:24.812 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build Failed with an exception.
11:08:24.822 [ERROR] [org.gradle.BuildExceptionReporter]
11:08:24.829 [ERROR] [org.gradle.BuildExceptionReporter] * Where:
11:08:24.834 [ERROR] [org.gradle.BuildExceptionReporter] Build file 'C:\Users\Work\AndroidProjects\RSSUnified\build.gradle' line: 114
11:08:24.840 [ERROR] [org.gradle.BuildExceptionReporter]
11:08:24.845 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
11:08:24.850 [ERROR] [org.gradle.BuildExceptionReporter] A problem occurred evaluating root project 'RSSUnified'.
11:08:24.855 [ERROR] [org.gradle.BuildExceptionReporter] > For input string: "21 rc11"
11:08:24.864 [ERROR] [org.gradle.BuildExceptionReporter]
11:08:24.870 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
11:08:24.875 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'RSSUnified'.
11:08:24.880 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFac
tory.java:54)
11:08:24.885 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.jav
a:127)

使用gradle 1.2

编辑:这是我的布局xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

</RelativeLayout>

这就是积极性

public class RSSListActivity extends Activity {

    /*
     * (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // Todo Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_activity_layout);
    }

}

项目结构如下:

├───.gradle
│   └───1.2
│       └───taskArtifacts
├───assets
├───bin
│   ├───classes
│   │   └───com
│   │       ├───jr
│   │       │   ├───screenLogic
│   │       │   └───screens
│   │       └───richy
│   │           └───RSSunified
│   └───res
├───build
│   └───gen
│       └───com
│           └───richy
│               └───RSSunified
├───gen
│   └───com
│       └───richy
│           └───RSSunified
├───res
│   ├───drawable-hdpi
│   ├───drawable-ldpi
│   ├───drawable-mdpi
│   ├───drawable-xhdpi
│   ├───layout
│   ├───values
│   ├───values-v11
│   └───values-v14
└───src
    └───com
        └───jr
            ├───screenLogic
            └───screens

这是项目的根文件夹中的内容

AndroidManifest.xml  assets  bin  build  build.gradle  gen  gradle.properties  ic_launcher-web.png  local.properties  project.properties  res  src

最终的android清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.richy.RSSunified"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />

    <application android:label="@string/app_name"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/AppTheme">

    </application>

</manifest>

Local.properties

sdk.dir = C:/Program Files (x86)/Android/android-sdk

project.properties

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-15

编辑:

我已经恢复到旧版本的adt / sdk插件并设法解决上述问题,但是在我这样做之后,我现在得到以下错误

15:24:24.558 [LIFECYCLE] [org.gradle.TaskExecutionLogger] :androidProcessResources Failed
15:24:24.571 [ERROR] [org.gradle.BuildExceptionReporter]
15:24:24.575 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build Failed with an exception.
15:24:24.582 [ERROR] [org.gradle.BuildExceptionReporter]
15:24:24.588 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
15:24:24.597 [ERROR] [org.gradle.BuildExceptionReporter] Execution Failed for task ':androidProcessResources'.
15:24:24.602 [ERROR] [org.gradle.BuildExceptionReporter] > Unexpected internal error near index 1
15:24:24.607 [ERROR] [org.gradle.BuildExceptionReporter]   \
15:24:24.613 [ERROR] [org.gradle.BuildExceptionReporter]    ^
15:24:24.621 [ERROR] [org.gradle.BuildExceptionReporter]
15:24:24.626 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
15:24:24.631 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution Failed for task ':androidProcessResources'.
15:24:24.636 [ERROR] [org.gradle.BuildExceptionReporter]        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecu
ter.java:68)

解决方法:

如下所述:
http://tools.android.com/tech-docs/new-build-system/using-the-new-build-system#TOC-Working-with-and-Customizing-SourceSets

Default sourceset location is under src/<sourceset>

您的sourceset名称是main,因此location是src / main

另外,描述了清单属性

manifest, type AndroidSourceFile, default location src/<sourceset>/AndroidManifest.xml

我猜清单的声明:

   manifest {
                srcFile 'AndroidManifest.xml'
            }

认值相同,最后是位置:

src/main/AndroidManifest.xml

在异常消息中列出.

我认为这是gradle android插件的工作原理.
如果我错了,请纠正我,我不知道Gradle.

编辑

好的,现在我知道出了什么问题.您的构建脚本混合了两个不同插件的设置.

更改:

classpath 'com.android.tools.build:gradle:0.1'

classpath 'org.gradle.api.plugins:gradle-android-plugin:1.2.1'

删除android块,但保持身体.

删除带有正文的sourceSets块.

然后它应该工作,我这次测试它.

编辑2

这是Windows相关的错误,修复6天前:

https://github.com/jvoegele/gradle-android-plugin/pull/89

你可以做的是下载最新的插件版本

git clone git://github.com/jvoegele/gradle-android-plugin.git

并将其安装在本地maven存储库中:

gradle install

然后将mavenLocal()添加到存储库:

repositories {
    mavenCentral()
    mavenLocal()
}

并将插件版本更改为快照:

dependencies {
    classpath 'org.gradle.api.plugins:gradle-android-plugin:1.2.2-SNAPSHOT'
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐