问题标签 [android-gradle-plugin]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
14634 浏览

android - Android studio Gradle :: dependencies {compile 'com.android.support:appcompat-v7:18.0.0' } 编译失败

我最近切换到 android studio 进行开发。我用minsdk、targetsdk 创建了项目,并用 sdk 编译为 Google Api Level 8。

由于 build.gradle 文件中的以下代码,项目编译失败。

谁能说出为什么会这样?

我的整个 build.gradle 发布在下面。

下面是截图 在此处输入图像描述

0 投票
3 回答
10251 浏览

android - “应在 Gradle 构建脚本中指定签名配置”......我做到了

当我来签署我的应用程序时,我遇到了一个大问题:我已经按照文档设置了签名配置:

但我仍然收到此错误消息:“应在 Gradle 构建脚本中指定签名配置”

在此处输入图像描述

0 投票
6 回答
38425 浏览

android - 如何将 Guava 添加到我的 Android Studio 项目中?

首先,我知道这个问题的存在——如何将库项目添加到 Android Studio?- 不幸的是,它对我没有帮助。

我的目标相当简单。我想使用 Android Studio IDE (0.2.11) 和代码中的Guava 库编写一个 Android 应用程序。

我不知道 Gradle,我才开始使用 Android Studio,而我的 Visual Studio/C# 背景让我很笨拙,对此我深表歉意(在那个米老鼠世界中,您通常只需添加一个库引用就可以了)。

我将用屏幕截图记录我的步骤。我主要遵循这个答案中给出的建议。

libraries我在我的项目文件夹下创建了一个文件夹。

在此处输入图像描述

我将 Guava 存储库克隆到其中。

在此处输入图像描述

文件成功出现。

在此处输入图像描述

我去Project Structure选择了Import Module

在此处输入图像描述

在此处输入图像描述

我选择Create module from existing sources并同意所有默认选项。

我将settings.gradle文件更新为include ':libraries:guava', ':Test'

在此处输入图像描述

我的build.gradle文件是compile project(":libraries:guava")

在此处输入图像描述

但是,每当我尝试重建项目时,我得到的只是:

我确实尝试build.gradle在文件夹中放入如下内容guava

(正如上述答案所说)。

我已经上下搜索以找到build.gradle番石榴的“正确”。

https://code.google.com/p/guava-libraries/wiki/UseGuavaInYourBuild - 也没有帮助我。

我确实尝试了无数的东西,我不会在这里描述,因为它们相当随意——我尝试添加一个模块依赖项,我尝试打开Use auto-importinGradle settings等。

我知道这不是解决问题的方法,我保证我会认真阅读从 1 到 5.4.2 到 7.3 的 Gradle用户指南,但我不敢相信这是实现仅仅添加一个库到一个不起眼的东西的真正先决条件项目?为什么没有默认build.gradle文件可以在必要时开始摆弄各种事情?

真正的问题- 我如何创建一个应用程序(在 Android Studio 中),该应用程序可以在 Android 设备上构建、实际运行,并且最重要的是允许我使用 Guava,这样我就可以按值对地图进行排序,而无需编写 50 行代码? :)

很抱歉我的问题的语气很啰嗦,我知道这里的操练,这只是我发泄沮丧的方式。

从解决类似问题的问题和答案的投票数来看,我敢肯定,我不是唯一一个会从更多说明中受益的人。我会立即开始赏金,但规则禁止我。

0 投票
4 回答
25058 浏览

android - Gradle android 为不同的处理器架构构建

我想使用 Gradle 为 4 个不同的 Android CPU 处理器架构(armeabi armeabi-v7a x86 mips)构建 4 个单独的 apk。

我在libs文件夹中有为 4 个 CPU 架构构建的原生 OpenCV 库。

我希望每个 apk 只包含对应正确 CPU 架构的 OpenCV 库。

当前的构建脚本如下:

有人可以帮我解决这个问题吗?

干杯,

0 投票
1 回答
37464 浏览

android - Gradle编译错误“没有方法签名”

当我尝试从终端运行 ./gradlew build.gradle 时,出现以下错误:

我尝试在根 build.gradle 文件以及子项目上应用 java 插件。但我仍然得到同样的错误。

我有以下项目结构:

其中顶级 build.gradle 包含:

settings.gradle 包含以下内容:

TestMobile -> build.gradle 包含以下内容:

ThirdParty/SlidingMenu -> build.gradle 包含以下内容:

0 投票
3 回答
12421 浏览

java - Android Gradle 项目中包括 Apache HttpComponents 的问题

我尝试使用 build.gradle 文件在我的应用程序中包含 httpmime,一切都编译得很好。相反,当应用程序尝试实际使用 MultipartEntityBuilder 类时,日志上有一堆 WARN 级别的消息表明存在问题。

这是我的 build.gradle 依赖项的摘录:

以下是错误:

java类:

[编辑] 正确的依赖关系,根据答案

[第二次编辑] 仍然有问题 - 现在是这些其他缺失的位,但它可能是后端的问题:

[另一个编辑]

在这种情况下,最后一点缺失的位似乎对 MultipartEntityBuilder 的成功使用没有任何影响。

0 投票
1 回答
1720 浏览

android - Android Studio 在旧版本上调用新方法

更新到 Android Studio 0.2.13 后,我遇到了大量关于 API 错误 ( Calling new methods on older versions) 的 lint 问题。成千上万的一个例子:

在此处输入图像描述 在此处输入图像描述

我教过 min sdk 是从 manifest.xml 中读出的?

我试图将它设置在大版本中,但这没有帮助。

谢谢 !

0 投票
1 回答
2096 浏览

android - 将时间戳系统属性从 Gradle 传递到 Android (Java) 应用程序

我希望我的 Android 应用程序在运行时知道应用程序的构建时间。我是 Gradle 的新手,但它看起来非常灵活,我认为无需任何外部帮助程序或令牌替换就可以实现这一点。

我的想法是在某种 Gradle 预构建任务中计算时间戳字符串。然后我想将此字符串作为系统属性传递给 Java 应用程序。例如:

然后在 Java 中检索运行时的时间戳:

我将如何编写必要的 Gradle 代码来实现这一目标?更具体地说,在哪里/如何调用我的自定义任务,是否可以以上述方式添加系统属性。

0 投票
1 回答
1835 浏览

android - Gradle: How do I actually use a custom dependency configuration OR swap external dependencies for local ones?

Question

In Gradle, given a custom dependency configuration, what's the simplest way to actually use/compile with it in Android? Alternatively, what's the best way to switch between 'local' and 'external' dependencies?

Problem

To make building easier and to make better use of multi-project builds, I've created a top-level "aggregator" project that others may or may not use. So any modifications to subprojects must be self-contained in the aggregator.

In the build process for this aggregator, I want to always use local versions of the subprojects (i.e. the source code I'm editing), rather than the compiled artifacts in our repository. Additionally, this aggregator will be used in our continuous integration environment, such that the unit tests of all subprojects are run on each code commit.

Details : partial solution

Given a flat folder structure similar to the following, where all projects/modules are decoupled such that children don't know anything about parents.

I've created the following build.gradle file in the top-most project:

The localProjects configurations are working properly and each has successfully replaced the existing dependencies (like 'com.mycompany:utils:1.0.0' and 'com.mycompany:models:1.0.0') with local projects. The only problem is I can't figure out how to get Android to use the 'localProjects' dependency set instead of the 'compile' one.

In pure java examples, I've seen people manually replace the classpath in the sourceSet but this doesn't work easily for the Android plugin.

Summary

How do you point an Android build to a custom dependency configuration such that it builds with those dependencies instead of the compile, debugCompile, releaseCompile ones?

Ultimately, I just want incremental builds to work. For example, if I edit the 'models' source code then:

  • The next time I build the app, it recompiles the 'models' project
  • It does not recompile the 'networking' or 'utils' code
  • These changes show up in the app, immediately, after building once (i.e. no more building in 3 or 4 places just to produce an APK with 'the latest')
  • As I make code changes to any of these projects, all I ever have to do is run the build from the aggregator project and the right things compile and the APK that's produced reflects the latest code on my machine
  • Similarly, I can run all unit tests just from the aggregator
  • Last but not least, I cannot edit the existing projects to accomplish this. All changes must be self-contained in the aggregator because there are other engineers on the project who may not choose to use it.

This is a very common use case and the Gradle team has mentioned adding better support for this kind of thing in the future. In the meantime, how do we solve this?

0 投票
2 回答
5638 浏览

android - 在 IntelliJ IDEA 中创建新的基于 Gradle 的 Android 项目

标题基本概括了所有内容。我想在 IntelliJ IDEA (13 EAP) 中创建一个新的基于 Gradle 的 Android 项目,就像在 Android Studio 中一样。

我尝试在 IntelliJ 中创建一个新的 Android 项目,但它使用“旧”构建系统,而创建一个新的 Gradle 项目会创建一个根本没有 Android 集成的通用 Java 项目。

我能做些什么?