You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native ViroSample AR项目无法完美构建的技术求助

Hey there! Let's work through this SO file conflict and build issue for your ViroSample React Native AR project on macOS High Sierra 10.13.6. You're right that tackling SO files one by one gets frustrating—here's a structured approach to audit all SO files at once and fix the root causes:

1. Generate a Full Report of All SO Files in Dependencies

First, we need to see exactly which .so files are coming from which dependencies, and where duplicates are happening. You can create a custom Gradle task to list every SO file across all your release dependencies:

Add this task to your app/build.gradle file (either inside the android block or at the top level):

task listAllSoFiles {
    doLast {
        configurations.releaseRuntimeClasspath.each { dependencyFile ->
            if (dependencyFile.name.endsWith('.aar') || dependencyFile.name.endsWith('.jar')) {
                zipTree(dependencyFile).visit { element ->
                    if (element.path.endsWith('.so')) {
                        println "SO File: ${element.path} | From Dependency: ${dependencyFile.name}"
                    }
                }
            }
        }
    }
}

Run this task in your terminal:

./gradlew app:listAllSoFiles

This will print a complete list of every SO file included in your release build, along with which AAR/JAR it's coming from. Look for duplicates (same SO path listed from multiple dependencies)—these are your conflict points.

2. Resolve SO Conflicts Targeted

Now that you know exactly what's duplicated, you can configure packagingOptions to handle them properly. Instead of adding random excludes, focus on two key actions:

  • pickFirst: Use this to prioritize critical SO files (like Viro's core AR libraries, since they're essential for your project functionality)
  • exclude: Use this for redundant SO files (e.g., x86 variants if you're only targeting ARM-based mobile devices)

Example configuration for app/build.gradle:

android {
    // ... your existing config (compileSdkVersion, defaultConfig, etc.)

    packagingOptions {
        // Prioritize Viro's core renderer and platform SO files
        pickFirst 'lib/armeabi-v7a/libviro_renderer.so'
        pickFirst 'lib/arm64-v8a/libviro_renderer.so'
        pickFirst 'lib/armeabi-v7a/libviro_platform.so'
        pickFirst 'lib/arm64-v8a/libviro_platform.so'

        // Exclude unused architectures to reduce APK size and avoid conflicts
        exclude 'lib/x86/**/*.so'
        exclude 'lib/x86_64/**/*.so'

        // Add other exclusions based on your duplicate report
        // e.g., exclude 'lib/armeabi-v7a/libgnustl_shared.so' if it's duplicated across dependencies
    }
}

3. Lock Down Gradle/AGP Versions to Match Viro Requirements

Viro React Native is picky about Android Gradle Plugin (AGP) and Gradle versions, especially on older macOS versions like High Sierra (which has Java 8 limits). Make sure your project uses compatible versions:

In your project-level build.gradle:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        // AGP 4.1.3 is compatible with Java 8 and Viro's requirements
        classpath 'com.android.tools.build:gradle:4.1.3'
        classpath 'com.facebook.react:react-native-gradle-plugin:+'
    }
}

In gradle/wrapper/gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

Gradle 6.5 is the latest version compatible with Java 8 and High Sierra, which avoids issues with newer Gradle versions that require Java 11.

4. Clean and Rebuild from Scratch

Old build artifacts can cause lingering SO file issues. Run these commands to wipe everything and start fresh:

./gradlew clean
./gradlew assembleRelease

After building, verify the final APK has the correct SO files by running:

unzip -l app/build/outputs/apk/release/app-release.apk | grep .so

This will list all SO files in your APK—confirm that duplicates are gone and all critical Viro SO files are present.

5. Add ProGuard Rules (If Using Minification)

If you're enabling minifyEnabled in Release mode, make sure you don't obfuscate Viro or ARCore classes, which can break AR functionality. Add these lines to app/proguard-rules.pro:

-keep class com.viro.** { *; }
-keep class com.google.ar.** { *; }
-keep class com.facebook.react.** { *; }

That should cover all bases to get a clean, working Release build of your ViroSample project. If you hit specific duplicate SO entries that need more targeted fixes, feel free to share the output from the listAllSoFiles task!

内容的提问来源于stack exchange,提问作者Abhinav Saxena

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:08:32