如何修复HelloCardboard示例的NDK构建错误 [英] How to fix NDK build error for HelloCardboard sample

查看:426
本文介绍了如何修复HelloCardboard示例的NDK构建错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译Google Cardboard Sdk示例.

我正在按照

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

  FAILURE:构建失败,发生异常.* 什么地方出了错:任务':hellocardboard-android:externalNativeBuildDebug'的执行失败.>生成命令失败.执行过程C:\ Users \ Shanu \ AppData \ Local \ Android \ Sdk \ cmake \ 3.10.2.4988404 \ bin \ ninja.exe时出现错误,参数为{-CC:\ Projects \ cardboard \ hellocardboard-android \ .cxx \ cmake \调试\ x86board_jni}忍者:输入目录`C:\ Projects \ cardboard \ hellocardboard-android \ .cxx \ cmake \ debug \ x86'忍者:错误:'../../../../build/intermediates/cmake/debug所需的'../../../../libraries/jni/x86/libcardboard_api.so'/obj/x86/libcardboard_jni.so",丢失,并且尚无已知规则* 尝试:使用--stacktrace选项运行以获取堆栈跟踪.使用--info或--debug选项运行,以获取更多日志输出.与--scan一起运行以获取完整的见解.*在https://help.gradle.org上获得更多帮助4秒内失败29项可执行的任务:2项已执行,27项最新下午1:55:12:任务执行完成了汇编". 

然后我尝试使用-stacktrace

 原因:org.gradle.internal.UncheckedException:构建命令失败. 

但是还有一个警告:

 警告:此应用程序仅具有32位[armeabi-v7a,x86]本机库.从2019年8月1日开始,Google Play商店要求所有包含本机库的应用程序都必须提供64位版本.有关更多信息,请访问https://g.co/64-bit-requirement 

嗯,这让我不知道,因为以前从未使用过NDK/Cardboard SDK.

这是 build.gradle(hellocardboard)的外观:

  apply插件:"com.android.application"安卓 {compileSdkVersion 29defaultConfig {applicationId"com.google.cardboard.hellocardboard"minSdkVersion 21targetSdkVersion 29版本代码1versionName"1.0"testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"ndk {abiFilters'armeabi-v7a','x86'}externalNativeBuild {cmake {cppFlags"-std = gnu ++ 11"参数"-DANDROID_STL = c ++ _ shared"}}}buildTypes {释放 {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'}}externalNativeBuild {cmake {路径"CMakeLists.txt"}}compileOptions {sourceCompatibility ='1.8'targetCompatibility ='1.8'}}依赖项{实现fileTree(dir:'libs',包括:['* .jar'])//noinspection GradleCompatible实施'com.android.support:appcompat-v7:28.0.0'实现'com.android.support.constraint:constraint-layout:1.1.3'//Android移动视觉实施'com.google.android.gms:play-services-vision:15.0.2'//noinspection GradleCompatible实施'com.android.support:design:28.0.0'实施项目(:sdk")}//NDK构建的依赖项位于.aar文件中,因此它们需要//在NDK目标可以链接之前提取.任务extractNdk(type:Copy){如果(file("$ {project.rootDir}/sdk/build/outputs/aar/sdk-release.aar").exists()){复制 {来自zipTree("$ {project.rootDir}/sdk/build/outputs/aar/sdk-release.aar")进入图书馆/"包括"jni/**/libcardboard_api.so"}复制 {来自"$ {project.rootDir}/sdk/include/cardboard.h"进入图书馆/"}}}任务deleteNdk(type:Delete){删除"libraries/jni"删除"libraries/cardboard.h"}build.dependsOn(extractNdk)clean.dependsOn(deleteNdk) 

这是整个项目托管在我的GitHub上

所有内容均采用Google的默认设置,除了配置外,我没有进行任何配置从SDK管理器安装以下组件:

  • CMake
  • LLDB
  • NDK(并排)

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

解决方案

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

示例应用程序告诉您单击Gradle选项卡中的组装"选项.您应该单击:sdk"下的汇编"选项,而不是不是:hellocardboard-android"下的一个.

官方说明尚不清楚;仅当您仔细查看那里的屏幕截图时,它才可见.

I am trying to compile Google Cardboard Sdk sample.

I am following instructions given by google's official docs

I am stuck at step 3, where I am supposed to assemble the project:

This is the error I am getting when I start to assemble:

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

Then I tried to run with --stacktrace

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

But there is an additional warning:

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

Well, that doesn't give me an idea, as to have never used NDK/Cardboard SDK ever before.

Here is how the build.gradle(hellocardboard) looks like:

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

Everything is at google's default settings, and I haven't configured anything, except Install these components from the SDK manager:

  • CMake
  • LLDB
  • NDK (Side by Side)

What is the issue here and how can I fix it?

解决方案

This usually happens when you haven't built the SDK.

The sample app tells you to click the "assemble" option in the Gradle tab. You should click the "assemble" option under ":sdk", not the one under ":hellocardboard-android".

The official instructions are unclear about this; it is only visible if you look closely at the screenshots there.

这篇关于如何修复HelloCardboard示例的NDK构建错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆