Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot build hello_ar_c sample with AGP 7.0 #1279

Closed
fuchg3 opened this issue Aug 14, 2021 · 4 comments
Closed

Cannot build hello_ar_c sample with AGP 7.0 #1279

fuchg3 opened this issue Aug 14, 2021 · 4 comments
Assignees
Labels

Comments

@fuchg3
Copy link

fuchg3 commented Aug 14, 2021

SPECIFIC ISSUE ENCOUNTERED

Cannot correctly build hello_ar_c sample when using Android Gradle Plugin 7.0

Gradle build output:

Executing tasks: [:app:assembleDebug] in project arcore-android-sdk\samples\hello_ar_c

> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:generateDebugBuildConfig
> Task :app:javaPreCompileDebug
> Task :app:checkDebugAarMetadata
> Task :app:generateDebugResValues
> Task :app:generateDebugResources
> Task :app:createDebugCompatibleScreenManifests
> Task :app:extractDeepLinksDebug
> Task :app:processDebugMainManifest
> Task :app:processDebugManifest
> Task :app:configureCMakeDebug

> Task :app:buildCMakeDebug FAILED
C/C++: ninja: error: '../../../../build/arcore-native/jni/arm64-v8a/libarcore_sdk_c.so', needed by '../../../../build/intermediates/cxx/Debug/211y60f3/obj/arm64-v8a/libhello_ar_native.so', missing and no known rule to make it

> Task :app:extractNativeLibraries
> Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
> Task :app:mergeDebugResources
> Task :app:mergeDebugShaders
> Task :app:compileDebugShaders NO-SOURCE
> Task :app:generateDebugAssets UP-TO-DATE
> Task :app:mergeDebugAssets
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:compressDebugAssets
> Task :app:mergeDebugJavaResource
> Task :app:desugarDebugFileDependencies
> Task :app:checkDebugDuplicateClasses
> Task :app:mergeDebugJniLibFolders
> Task :app:processDebugManifestForPackage
> Task :app:mergeExtDexDebug
> Task :app:mergeLibDexDebug
> Task :app:mergeDebugNativeLibs
> Task :app:validateSigningDebug
> Task :app:stripDebugDebugSymbols
> Task :app:writeDebugAppMetadata
> Task :app:writeDebugSigningConfigVersions
> Task :app:processDebugResources
> Task :app:compileDebugJavaWithJavac
> Task :app:dexBuilderDebug
> Task :app:mergeProjectDexDebug
> Task :app:packageDebug

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:buildCMakeDebug'.
> Build command failed.
  Error while executing process AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C arcore-android-sdk\samples\hello_ar_c\app\.cxx\Debug\211y60f3\arm64-v8a hello_ar_native}
  ninja: Entering directory `arcore-android-sdk\samples\hello_ar_c\app\.cxx\Debug\211y60f3\arm64-v8a'
  
  ninja: error: '../../../../build/arcore-native/jni/arm64-v8a/libarcore_sdk_c.so', needed by '../../../../build/intermediates/cxx/Debug/211y60f3/obj/arm64-v8a/libhello_ar_native.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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1m 6s
32 actionable tasks: 32 executed

It seems task extractNativeLibraries run after task that should depend on it.

VERSIONS USED

  • Android Studio: Android Studio Arctic Fox | 2020.3.1
  • Android Gradle Plugin: 7.0.0
  • Gradle: 7.0.2
  • ARCore SDK for Android: 1.26.0
  • O/S: Windows 10 21H1

STEPS TO REPRODUCE THE ISSUE

  1. Open hello_ar_c sample project in Android Studio
  2. Update AGP version to 7.0.0 and Gradle version to 7.0.2
  3. Build project

ADDITIONAL COMMENTS

Change

task-> if (task.name.contains("external") && !task.name.contains("Clean"))

to

task-> if (task.name.contains("configureCMake"))

would build successfully. However, sample app crashed due to UnsatisfiedLinkError.

Error logcat:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.google.ar.core.examples.c.helloar, PID: 13955
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.google.ar.core.examples.c.helloar-zrzzeNfjkImFMMLm0cqrww==/base.apk"],nativeLibraryDirectories=[/data/app/com.google.ar.core.examples.c.helloar-zrzzeNfjkImFMMLm0cqrww==/lib/arm64, /data/app/com.google.ar.core.examples.c.helloar-zrzzeNfjkImFMMLm0cqrww==/base.apk!/lib/arm64-v8a, /system/lib64, /hw_product/lib64, /system/product/lib64, /prets/lib64]]] couldn't find "libhello_ar_native.so"
        at java.lang.Runtime.loadLibrary0(Runtime.java:1067)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
        at java.lang.System.loadLibrary(System.java:1668)
        at com.google.ar.core.examples.c.helloar.JniInterface.<clinit>(JniInterface.java:30)
        at com.google.ar.core.examples.c.helloar.HelloArActivity.onCreate(HelloArActivity.java:131)
        at android.app.Activity.performCreate(Activity.java:8214)
        at android.app.Activity.performCreate(Activity.java:8202)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4033)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4247)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2613)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:219)
        at android.app.ActivityThread.main(ActivityThread.java:8668)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

If you analyzed output apk, you would find libhello_ar_native.so hasn't been packed. Though it do exist in build directory arcore-android-sdk\samples\hello_ar_c\app\build\intermediates\cmake\debug\obj\arm64-v8a.

@fuchg3 fuchg3 added the bug label Aug 14, 2021
@fuchg3
Copy link
Author

fuchg3 commented Aug 14, 2021

https://issuetracker.google.com/189366123 may be relevant.

@fuchg3
Copy link
Author

fuchg3 commented Aug 18, 2021

Probably affected by this issue Android Gradle Plugin 7.0.0 does not include jniLibs in APK if tasks.whenTaskAdded closure is used

Replace tasks.whenTaskAdded closure should fix it, here's my workaround

// Extracts the shared libraries from aars in the natives configuration.
// This is done so that NDK builds can access these libraries.
def taskExtractNativeLibs = tasks.register('extractNativeLibs') {
    // Always extract, this insures the native libs are updated if the version changes.
    outputs.upToDateWhen { false }
    doFirst {
        configurations.natives.files.each { f ->
            copy {
                from zipTree(f)
                into arcore_libpath
                include "jni/**/*"
            }
        }
    }
}

def nativeBuildTasks = tasks.matching { task ->
    task.name.contains('configureCMake')
}

nativeBuildTasks.configureEach { task ->
    task.dependsOn(taskExtractNativeLibs)
}

@devbridie devbridie self-assigned this Aug 18, 2021
@devbridie devbridie pinned this issue Aug 18, 2021
@devbridie
Copy link
Member

Workaround seems great; thanks for investigating. Per issue 196413674#5, it seems like an bugfix update will fix this soon.

@devbridie
Copy link
Member

As per 196413674#comment7, this has been cherry picked to 2020.3.1, and I've confirmed that building now works out of the box without the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants