Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用gradle构建android项目_Android_Build_Gradle - Fatal编程技术网

无法使用gradle构建android项目

无法使用gradle构建android项目,android,build,gradle,Android,Build,Gradle,我在使用Gradle构建一个简单的android项目时遇到了困难。我的生成文件如下: buildscript { repositories { mavenCentral() // To use a development snapshot version of the plugin, add the // Sonatype Snapshots repository. maven { url "https://oss.sona

我在使用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
  }
使用Gradle1.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>
项目结构如下:

├───.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>
   manifest {
                srcFile 'AndroidManifest.xml'
            }
project.properties

sdk.dir = C:/Program Files (x86)/Android/android-sdk
# 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)

在我看来,就像任务
androidProcessResources
所指示的那样,您试图在一个Android资源文件中错误地转义反斜杠。请检查您的资源文件或将其发布到此处,以便我们查看。

如中所述:

默认源集位置位于
src/

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

此外,还描述了清单属性:

清单,键入AndroidSourceFile,默认位置
src//AndroidManifest.xml

我猜舱单声明:

<?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>
   manifest {
                srcFile 'AndroidManifest.xml'
            }
与默认值相同,并以位置结束:

src/main/AndroidManifest.xml
在异常消息中列出

我想这就是gradle android插件的工作原理。
如果我错了,请纠正我,我不认识格雷德尔

编辑 好了,现在我知道怎么了。您的构建脚本混合了来自两个不同插件的设置

更改:

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

移除
android
块,但保留主体

删除带有主体的
sourceset

那么它应该可以工作了,这次我测试了它

编辑2 这是与Windows相关的错误,已在6天前修复:

你能做的就是下载最新的插件版本

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

如果你愿意接受你在过去几天里提出的其他问题的答案,人们会更愿意帮助你。我愿意,但这没什么区别,我认为这个问题不容易回答。另外,当人们添加评论而不是答案时,我不能接受他们。它必须作为答案发布。我已经从仅仅发表评论的人那里得到了答案。公平地说,我的一些问题我没有找到一个有效的答案,所以我很难接受一个答案,但现在我会尝试接受更多。我将在这里接受一个有效的答案,这个答案适用于我正在讨论的问题。找到我的gradle版本:在Android Studio中,转到文件>项目结构。然后选择左侧的“项目”选项卡。如果您使用的是Gradle包装器,那么您的项目将有一个Gradle/wrapper/Gradle-wrapper.properties文件夹。这决定了您使用的是哪个版本的Gradle。您好。我的res布局文件包含一个xml文件,该文件仅创建一个relativeLayout。我基本上创建了一个全新的项目,创建了一个带有简单布局的空白活动,只是为了看看我是否可以使用gradle构建和创建一个apk文件。检查我编辑的文章中的这些文件你有没有将项目上传到存储库,这样我就可以自己试用它?没有,在我的本地机器上。我已经更新了我的代码,并尝试和调整了一些东西,关于“/”的原始错误信息消失了。我知道有一个不同的生成错误,说明如何定位AndroidManifest。错误消息表示,我猜文件需要位于以下位置:
C:\Users\richardsj\Work\AndroidProjects\RssUnified\src\main\AndroidManifest.xml
。看起来是这样的。但是,如果我将目录和清单移动到那里,我就不能再通过eclipse在本地构建它,因为它会抱怨将src文件、res文件和清单文件弄错,因为将所有内容移动到src/main下会破坏默认的android结构。我不能指定源集的位置吗?好的。我不再出现该错误,但现在出现了此错误:*出了什么问题:在评估根项目“RssUnified”时出现了问题。>对于输入字符串:“21 rc11”让我更新我的问题,这可能是不同的问题。我不知道
RssUnified\build.gradle'行中的内容:114
。它似乎与最新的ADT有关。第114行是“应用插件:'android'”。这个构建脚本适合我。我有ADT 20.0.3-最新的稳定版本,而不是ADT 21的候选版本11。尝试删除此软件包并使用SDK管理器安装最新版本。
dependencies {
    classpath 'org.gradle.api.plugins:gradle-android-plugin:1.2.2-SNAPSHOT'
}