Gradle 在 android 工作室项目中集成 DroidAR 时出现构建错误

Gradle build errors while integrating DroidAR in an android studio project

我们提供了将 DroidAR 集成到 Eclipse 项目中的指南 link:DroidAR Mobile Augmented Reality - How to use the framework in your own application 但我在 AndroidStudio 项目中设置 DroidAR 时遇到了困难。

我遵循的步骤是:

  1. 从这里下载 DroidAR link - DroidAR
  2. 创建了一个新的 android 工作室项目 - DroidArSample
  3. 导入 droidar 文件夹(在下载的存档中找到,第 2 步)作为 DroidArSample 中的新模块
  4. 添加了 droidar 作为 DroidArSample 的依赖项
  5. 从 droidar/AndroidManifest 中删除了图标相关属性。xml
  6. 已编译

它显示了 120 个编译错误,下面指定了几个错误:

AGPBI: {"kind":"error","text":"Error retrieving parent for item: No resource found that matches the given name \u0027android:Widget.Material.Spinner.Underlined\u0027.","sources":[{"file":"/Users/devarshi.k/Downloads/DroidArSample/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.0/res/values-ldltr-v21/values-ldltr-v21.xml","position":{"startLine":1}}],"original":""}
AGPBI: {"kind":"error","text":"Error retrieving parent for item: No resource found that matches the given name \u0027android:Widget.Material.Spinner.Underlined\u0027.","sources":[{"file":"/Users/devarshi.k/Downloads/DroidArSample/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.0/res/values-ldrtl-v23/values-ldrtl-v23.xml","position":{"startLine":1}}],"original":""}
AGPBI: {"kind":"error","text":"No resource found that matches the given name: attr \u0027android:textAlignment\u0027.","sources":[{"file":"/Users/devarshi.k/Downloads/DroidArSample/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.0/res/values-v17/values-v17.xml","position":{"startLine":5,"startColumn":20,"startOffset":407,"endColumn":41,"endOffset":428}}],"original":""}

最终失败消息是:

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/devarshi.k/Library/Android/sdk/build-tools/22.0.1/aapt'' finished with non-zero exit value 1

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

有什么想法吗?

将下一行添加到您的 build.gradle

android {
    ...
    compileOptions.encoding = 'ISO-8859-1' // write your encoding here
    ...
}

检查您的 build.gradle 文件是否存在以下版本不匹配

  1. compileSdkVersion
  2. buildToolsVersion
  3. targetSdkVersion
  4. 包括应用程序兼容库,例如compile 'com.android.support:appcompat-v7:23.0.0'

建议全部设置为同一个版本,避免出现问题

例如 如果您使用 API 级别 23,您在 build.gradle 中的配置应该如下所示:

(以下各处声明)

compileSdkVersion 23

buildToolsVersion "23.0.0"

targetSdkVersion 23

compile 'com.android.support:appcompat-v7:23.0.0'

Refererence

我从 GitHub 下载了您的项目并以这种方式编辑了 build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    ...

defaultConfig {
        applicationId "daemonconstruction.droidarsample"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
     dependencies {
       ...
       compile 'com.android.support:appcompat-v7:22.+'
       ...
}

}

同步,重建项目,它工作。