0

我正在尝试在我的 macOS High Sierra 10.13.6 机器上构建这个 ReactNative 项目。这是基于 ReactNative 的增强现实解决方案:

病毒样本

我的项目级别 gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
         classpath 'com.android.tools.build:gradle:3.5.3'
        //noinspection GradleDependency
//        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'de.undercouch:gradle-download-task:4.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

ext {
    minSdkVersion = 23
    compileSdkVersion = 28
    buildToolsVersion = "28.0.3"
    targetSdkVersion = 28
    supportVersion = "28.0.0"
    mFacebookReactNativeVersion = "0.20.1"
    applicationId = "com.virosample"
    versionCode = 1
    versionName = "1.0"
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            url 'https://maven.google.com/'
        }
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        configurations.all {
            resolutionStrategy {
                dependencySubstitution {
                    substitute module("com.facebook.react:react-native:$mFacebookReactNativeVersion") with project(":ReactAndroid")
                }
            }
        }

    }
}

我的 App 模块级 gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */
def jscFlavor = 'org.webkit:android-jsc:r245459'

//def enableHermes = project.ext.react.get("enableHermes", false);

project.ext.react = [
    entryFile: "index.js"
    // your index js if not default, other settings
    // Hermes JSC ?
    // enableHermes: true
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = true

android {

    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    flavorDimensions "platform"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId rootProject.ext.applicationId
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        multiDexEnabled true
        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    productFlavors {
        ar {
            resValue 'string', 'app_name', 'ViroSample-ar'
            buildConfigField 'String', 'VR_PLATFORM', '"GVR"' //default to GVR
        }
        gvr {
            resValue 'string', 'app_name', 'ViroSample-gvr'
            buildConfigField 'String', 'VR_PLATFORM', '"GVR"'
        }
        ovr {
            resValue 'string', 'app_name', 'ViroSample-ovr'
            applicationIdSuffix '.ovr'
            buildConfigField 'String', 'VR_PLATFORM', '"OVR_MOBILE"'
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(':ReactAndroid')
    implementation "com.android.support:appcompat-v7:$supportVersion"
    implementation "com.facebook.react:react-native:$mFacebookReactNativeVersion"
//    ==
    implementation project(':arcore_client') // remove this if AR not required
    implementation project(':gvr_common')
    implementation project(path: ':viro_renderer')
    implementation project(path: ':react_viro')
//    ==
    implementation 'com.google.android.exoplayer:exoplayer:2.7.1'
    implementation 'com.google.protobuf.nano:protobuf-javanano:3.2.0rc2'
    implementation 'com.amazonaws:aws-android-sdk-core:2.16.5'
    implementation 'com.amazonaws:aws-android-sdk-ddb:2.16.5'
    implementation 'com.amazonaws:aws-android-sdk-ddb-mapper:2.16.5'
    implementation 'com.amazonaws:aws-android-sdk-cognito:2.16.5'
    implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.16.5'
    implementation jscFlavor
//    if (enableHermes) {
//      // For RN 0.60.x
//      // def hermesPath = "../../node_modules/hermesvm/android/"
//
//      // --- OR ----
//
//      // for RN 0.61+
//      def hermesPath = "../../node_modules/hermes-engine/android/";
//
//
//      debugImplementation files(hermesPath + "hermes-debug.aar")
//      releaseImplementation files(hermesPath + "hermes-release.aar")
//    } else {
//      implementation jscFlavor
//    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

我的settings.gradle:

rootProject.name = 'ViroSample'

include ':app'
//
include ':react_viro', ':arcore_client', ':gvr_common', ':viro_renderer'
project(':arcore_client').projectDir = new File('../node_modules/react-viro/android/arcore_client')
project(':gvr_common').projectDir = new File('../node_modules/react-viro/android/gvr_common')
project(':viro_renderer').projectDir = new File('../node_modules/react-viro/android/viro_renderer')
project(':react_viro').projectDir = new File('../node_modules/react-viro/android/react_viro')
//
include ':ReactAndroid'
//
project(':ReactAndroid').projectDir = new File(
    rootProject.projectDir, '../node_modules/react-native/ReactAndroid')

在发布模式和各种 gradle 类路径中有几个输出:

请看评论。

但是没有完美的工作构建,我可以与我的客户分享。


更新: 我目前正在将这些行添加到我的 app/build.gradle 中,在我的 'android{}' 范围内。

packagingOptions {
//        pickFirst 'lib/armeabi-v7a/libRSSupport.so'
//        pickFirst 'lib/arm64-v8a/libRSSupport.so'
//        pickFirst 'lib/x86_64/libRSSupport.so'
//        pickFirst 'lib/x86/libRSSupport.so'
//        pickFirst 'lib/arm64-v8a/librsjni.so'
//        pickFirst 'lib/x86/librsjni.so'
//        pickFirst 'lib/x86_64/librsjni.so'
//        pickFirst 'lib/armeabi-v7a/librsjni.so'
//        pickFirst 'lib/x86_64/librsjni_androidx.so'
//        pickFirst 'lib/armeabi-v7a/librsjni_androidx.so'
//        pickFirst 'lib/x86/librsjni_androidx.so'
//        pickFirst 'lib/arm64-v8a/librsjni_androidx.so'
        pickFirst 'lib/x86_64/libyoga.so'
        pickFirst 'lib/arm64-v8a/libjsinspector.so'
        pickFirst 'lib/arm64-v8a/libc++_shared.so'
        pickFirst 'lib/x86/libjscexecutor.so'
        pickFirst 'lib/x86/libjsc.so'
        pickFirst 'lib/armeabi-v7a/libglog_init.so'
//        pickFirst
//        pickFirst
//        pickFirst
//        pickFirst
//        pickFirst
    }
    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
        jni.srcDirs = [] //disable automatic ndk-build call
    }

这个列表每次都会不断构建新的错误。是否可以一次检查所有 SO 文件的重新生成?

4

1 回答 1

0

Step1:启用jetifier并迁移到AndroidX:

android.useAndroidX=true
android.enableJetifier=true

第2步:因为我已经在正确的轨道上。但是要消除每个重复的 SO 文件是乏味的。我这里有所有的清单。

每当您发现任何生成的重复 SO 文件时,请记住每个文件都有四个版本。所以你必须消除所有:

对于 libglog.so,您必须取消注释以下内容:

packagingOptions {
//        pickFirst 'lib/x86/libglog.so'
//        pickFirst 'lib/x86_64/libglog.so'
//        pickFirst 'lib/armeabi-v7a/libglog.so'
//        pickFirst 'lib/arm64-v8a/libglog.so'
}

我完成的清单如下:

packagingOptions {
        pickFirst 'lib/armeabi-v7a/libRSSupport.so'
        pickFirst 'lib/arm64-v8a/libRSSupport.so'
        pickFirst 'lib/x86_64/libRSSupport.so'
        pickFirst 'lib/x86/libRSSupport.so'
        pickFirst 'lib/arm64-v8a/librsjni.so'
        pickFirst 'lib/x86/librsjni.so'
        pickFirst 'lib/x86_64/librsjni.so'
        pickFirst 'lib/armeabi-v7a/librsjni.so'
        pickFirst 'lib/x86_64/librsjni_androidx.so'
        pickFirst 'lib/armeabi-v7a/librsjni_androidx.so'
        pickFirst 'lib/x86/librsjni_androidx.so'
        pickFirst 'lib/arm64-v8a/librsjni_androidx.so'
//        ==
        pickFirst 'lib/armeabi-v7a/libc++_shared.so'
        pickFirst 'lib/x86/libc++_shared.so'
        pickFirst 'lib/arm64-v8a/libc++_shared.so'
        pickFirst 'lib/x86_64/libc++_shared.so'
        pickFirst 'lib/arm64-v8a/libjsc.so'
        pickFirst 'lib/armeabi-v7a/libjsc.so'
        pickFirst 'lib/x86/libjsc.so'
        pickFirst 'lib/x86_64/libjsc.so'
//
        pickFirst 'lib/x86_64/libyoga.so'
        pickFirst 'lib/arm64-v8a/libyoga.so'
        pickFirst 'lib/x86/libyoga.so'
        pickFirst 'lib/armeabi-v7a/libyoga.so'
        pickFirst 'lib/arm64-v8a/libjsinspector.so'
        pickFirst 'lib/x86_64/libjsinspector.so'
        pickFirst 'lib/x86/libjsinspector.so'
        pickFirst 'lib/armeabi-v7a/libjsinspector.so'
        pickFirst 'lib/x86/libjscexecutor.so'
        pickFirst 'lib/armeabi-v7a/libjscexecutor.so'
        pickFirst 'lib/x86_64/libjscexecutor.so'
        pickFirst 'lib/arm64-v8a/libjscexecutor.so'
        pickFirst 'lib/x86/libglog_init.so'
        pickFirst 'lib/x86_64/libglog_init.so'
        pickFirst 'lib/armeabi-v7a/libglog_init.so'
        pickFirst 'lib/arm64-v8a/libglog_init.so'
        pickFirst 'lib/x86/libfb.so'
        pickFirst 'lib/x86_64/libfb.so'
        pickFirst 'lib/armeabi-v7a/libfb.so'
        pickFirst 'lib/arm64-v8a/libfb.so'
        pickFirst 'lib/x86/libfolly_json.so'
        pickFirst 'lib/x86_64/libfolly_json.so'
        pickFirst 'lib/armeabi-v7a/libfolly_json.so'
        pickFirst 'lib/arm64-v8a/libfolly_json.so'
        pickFirst 'lib/x86/libglog.so'
        pickFirst 'lib/x86_64/libglog.so'
        pickFirst 'lib/armeabi-v7a/libglog.so'
        pickFirst 'lib/arm64-v8a/libglog.so'
        pickFirst 'lib/x86/libreactnativejni.so'
        pickFirst 'lib/x86_64/libreactnativejni.so'
        pickFirst 'lib/armeabi-v7a/libreactnativejni.so'
        pickFirst 'lib/arm64-v8a/libreactnativejni.so'
//
//        pickFirst 'lib/x86/libglog.so'
//        pickFirst 'lib/x86_64/libglog.so'
//        pickFirst 'lib/armeabi-v7a/libglog.so'
//        pickFirst 'lib/arm64-v8a/libglog.so'
    }

请检查删除以下条目是否可以帮助您创建构建:

            pickFirst 'lib/armeabi-v7a/libRSSupport.so'
            pickFirst 'lib/arm64-v8a/libRSSupport.so'
            pickFirst 'lib/x86_64/libRSSupport.so'
            pickFirst 'lib/x86/libRSSupport.so'
            pickFirst 'lib/arm64-v8a/librsjni.so'
            pickFirst 'lib/x86/librsjni.so'
            pickFirst 'lib/x86_64/librsjni.so'
            pickFirst 'lib/armeabi-v7a/librsjni.so'
            pickFirst 'lib/x86_64/librsjni_androidx.so'
            pickFirst 'lib/armeabi-v7a/librsjni_androidx.so'
            pickFirst 'lib/x86/librsjni_androidx.so'
            pickFirst 'lib/arm64-v8a/librsjni_androidx.so'

它现在正在工作。

于 2020-01-03T06:57:53.973 回答