androidcmakeandroid-ndkgoogle-cardboardgoogle-vr-sdk

How to fix NDK build error for HelloCardboard sample


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:

enter image description here

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:

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


Solution

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