【问题标题】:Wix React-Native-Navigation V2 RN57 SupportWix React-Native-Navigation V2 RN57 支持
【发布时间】:2018-10-03 10:09:14
【问题描述】:

android/build.gradle

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

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 19
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
    }
    repositories {
        jcenter()
        google()
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'

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

allprojects {
    repositories {
        google()
        mavenLocal()
        mavenCentral()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support' && requested.name != 'multidex') {
            details.useVersion "${rootProject.ext.supportLibVersion}"
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

settings.gradle

rootProject.name = 'XProj1'

include ':app'

include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/lib/android/app/')

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

app/build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

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

def enableSeparateBuildPerCPUArchitecture = false

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

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.xproj1"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        missingDimensionStrategy "RNN.reactNativeVersion", "reactNative57"
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // 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]
            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
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support' && requested.name != 'multidex') {
            details.useVersion "${rootProject.ext.supportLibVersion}"
        }
    }
}


dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation project(':react-native-navigation')
    implementation 'com.android.support:design:25.4.0'
    implementation "com.android.support:multidex:1.0.3"
}

// 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'
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xproj1">
    <application
        android:name="android.support.multidex.MultiDexApplication" >
    </application>
</manifest>

MainActivity.java

package com.xproj1;

//import com.facebook.react.ReactActivity;
import com.reactnativenavigation.NavigationActivity;

public class MainActivity extends NavigationActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
//    @Override
//    protected String getMainComponentName() {
//        return "XProj1";
//    }
}

MainApplication.java

package com.xproj1;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import com.reactnativenavigation.react.ReactGateway;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends NavigationApplication{
  @Override
  protected ReactGateway createReactGateway() {
    ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
      @Override
      protected String getJSMainModuleName() {
        return "index";
      }
    };
    return new ReactGateway(this, isDebug(), host);
  }

  @Override
  public boolean isDebug() {
    return BuildConfig.DEBUG;
  }

  protected List<ReactPackage> getPackages() {
    // Add additional packages you require here
    // No need to add RnnPackage and MainReactPackage
    return Arrays.<ReactPackage>asList(
            // eg. new VectorIconsPackage()
    );
  }

  @Override
  public List<ReactPackage> createAdditionalReactPackages() {
    return getPackages();
  }
}

Wix 'React-Native-Navigation' V2 不支持 RN 57。我已经尝试了此 PR PR for RN 57 Support 中的所有方法。仍然面临问题。任何人都可以写一篇关于如何将导航与 RN 57 支持集成的快速中等帖子。

【问题讨论】:

    标签: react-native navigation wix-react-native-navigation


    【解决方案1】:
    1. react-native 和 jitpack 都需要 maven android/build.gradle

      allprojects {
        repositories {
             mavenLocal()
             mavenCentral()
             google()
             jcenter()
        maven 
         { url "$rootDir/../node_modules/react-native/android"}
         maven 
         { url 'https://jitpack.io' }
        }
      }
      
    2. 忽略其他 RNN 风格android/build.gradle 的末尾 添加以下提及代码。

        subprojects { subproject ->
           afterEvaluate {
           if ((subproject.plugins.hasPlugin('android') || 
          subproject.plugins.hasPlugin('android-library'))) {
          android {
              variantFilter { variant ->
                  def names = variant.flavors*.name
                  if (names.contains("reactNative51") || 
                names.contains("reactNative55")) {
                      setIgnore(true)
                  }
              }
            }
          }
       }
      }
      

    【讨论】:

      【解决方案2】:

      只需执行 yarn add https://github.com/leonardoballand/react-native-navigation-rn57.git 即可,只需按照 Wix 库说明进行操作即可。

      【讨论】:

      • 遇到了同样的问题。任务 ':react-native-navigation:compileReactNative57DebugJavaWithJavac' 执行失败。
      • 抱歉,您的解决方案不起作用,我仍然收到错误消息。
      【解决方案3】:

      我能够运行 react-native-navigation@^2.1.2 以及 react-native@^0.57.5react@16.6.1

      我能发现的唯一区别是我添加了RNN flavors configuration,尽管它没有在官方文档中作为强制性步骤突出显示。

      app/build.gradle

      subprojects { subproject ->
          afterEvaluate {
              if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
                  android {
                      variantFilter { variant ->
                          def names = variant.flavors*.name
                          if (names.contains("reactNative51") || names.contains("reactNative55") || names.contains("reactNative56")) {
                              setIgnore(true)
                          }
                      }
                  }
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2018-12-03
        • 2019-10-22
        • 2018-12-02
        • 2018-11-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多