android - 如何修复 HelloCardboard 示例的 NDK 构建错误

标签 android cmake android-ndk google-cardboard google-vr-sdk

我正在尝试编译 Google Cardboard SDK 示例。

我正在按照 google's official docs 给出的说明进行操作

我卡在了第 3 步,我应该在那里组装项目:

enter image description here

这是我开始组装时遇到的错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':hellocardboard-android:externalNativeBuildDebug'.
> Build command failed.
  Error while executing process C:\Users\Shanu\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C C:\Projects\cardboard\hellocardboard-android\.cxx\cmake\debug\x86 cardboard_jni}
  ninja: Entering directory `C:\Projects\cardboard\hellocardboard-android\.cxx\cmake\debug\x86'

  ninja: error: '../../../../libraries/jni/x86/libcardboard_api.so', needed by '../../../../build/intermediates/cmake/debug/obj/x86/libcardboard_jni.so', missing and no known rule to make it


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

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
29 actionable tasks: 2 executed, 27 up-to-date
1:55:12 PM: Task execution finished 'assemble'.

然后我尝试使用 --stacktrace 运行

Caused by: org.gradle.internal.UncheckedException: Build command failed.

但是还有一个额外的警告:

WARNING: This app only has 32-bit [armeabi-v7a,x86] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement

嗯,这并没有给我一个想法,因为我以前从未使用过 NDK/Cardboard SDK。

这是 build.gradle(hellocardboard) 的样子:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.google.cardboard.hellocardboard"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        ndk {
            abiFilters 'armeabi-v7a', 'x86'
        }
        externalNativeBuild {
            cmake {
                cppFlags "-std=gnu++11"
                arguments "-DANDROID_STL=c++_shared"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    // Android Mobile Vision
    implementation 'com.google.android.gms:play-services-vision:15.0.2'
    //noinspection GradleCompatible
    implementation 'com.android.support:design:28.0.0'
    implementation project(":sdk")
}

// The dependencies for NDK builds live inside the .aar files so they need to
// be extracted before NDK targets can link against.
task extractNdk(type: Copy)  {
    if (file("${project.rootDir}/sdk/build/outputs/aar/sdk-release.aar").exists()) {
        copy {
            from zipTree("${project.rootDir}/sdk/build/outputs/aar/sdk-release.aar")
            into "libraries/"
            include "jni/**/libcardboard_api.so"
        }
        copy {
            from "${project.rootDir}/sdk/include/cardboard.h"
            into "libraries/"
        }
    }
}

task deleteNdk(type: Delete) {
    delete "libraries/jni"
    delete "libraries/cardboard.h"
}

build.dependsOn(extractNdk)
clean.dependsOn(deleteNdk)

Here is the whole project hosted on my GitHub

一切都是谷歌的默认设置,我没有配置任何东西,除了 从 SDK 管理器安装这些组件:

  • CMake
  • LLDB
  • NDK(并排)

这是什么问题,我该如何解决?

最佳答案

这通常发生在您尚未构建 SDK 时。

示例应用会告诉您单击 Gradle 选项卡中的“组装”选项。您应该点击“:sdk”下的“assemble”选项,而不是“:hellocardboard-android”下的选项。

官方说明对此并不清楚;只有仔细查看那里的屏幕截图才能看到它。

关于android - 如何修复 HelloCardboard 示例的 NDK 构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61008108/

相关文章:

android - Firebase + Ionic + Cordova s​​ignInWithRedirect 重定向到 Android 上的本地主机

c++ - 使用 Visual Studio 2015 x64 和 CMake 构建 TBB

android - ndk-build找不到jni目录下的文件

android - 无法在 Qt Creator 中构建 Android APK

android - overridePendingTransition 不适用于 android 2.3.5

java - 使用 Parse SDK 的 Android Gradle 构建错误

c++ - 管理 cmake 依赖 git 模块

java - Android Studio NDK 解决方法

android - 使用 Firebase 在我的 Android 应用程序中验证两种类型的用户(学生和司机)的最佳方法是什么

linker - 使用 CMake 链接到 Armadillo 库