Tipsi-stripe Не удалось вызвать deviceSupportNativePay на android, iOS работает нормально - PullRequest
0 голосов
/ 16 апреля 2020

До того как я отправил вопрос

[] Я прочитал руководство по установке
[] Я знаю, что для iOS мне нужно установить модули, потому что я ' прочитали руководство по установке
[] Я прочитал руководство по связыванию и проверил, что все в порядке, как в руководство по связыванию
[] Я знаю, что перед использованием tipsi-stripe мне нужно установить параметры для моего приложения, как описано в руководстве по использованию

Проблема

Ошибка при Android при попытке вызвать функция deviceSupportNativePay, ошибка, показанная на рисунке ниже

https://user-images.githubusercontent.com/54148306/79314833-6cde0680-7f2c-11ea-888d-e1836c038f98.png

Поскольку я использую RN 0.61.5, сначала я не использую ручную ссылку, и на iOS работает просто отлично, но не на android. Сейчас я пробую ручную ссылку для android, но все же проблема. За этим последовало множество вопросов по stackoverflow и github без удачи. Может подтвердить, что объект чередования не является нулевым, потому что уже инициировал его с помощью setOptions.

Среда

  • tipsi-stripe версия: 7.2.0
  • Последняя tipsi-stripe версия где проблема не была воспроизведена (если применимо):
  • iOS или Android: Android
  • Версия ОС: любая версия
  • React-Native версия: 0.61 .5
  • (только Android) com.google.firebase:firebase-core версия: 16.0.9
  • (* Android только) com.google.android.gms:play-services-base версия: 16.1.0

Связанная конфигурация

/ app / build.gradle

apply plugin: "com.android.application"
apply plugin: "io.fabric"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,  // clean and rebuild if changing,
    bundleAssetName: "index.android.bundle",
    bundleInAlpha: true,
    bundleInBeta: true
]

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

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

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        missingDimensionStrategy 'react-native-camera', 'general'
        multiDexEnabled true
        renderscriptTargetApi 23
        renderscriptSupportModeEnabled true
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        // debug {
        //     signingConfig signingConfigs.debug
        // }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.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:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            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
            }

        }
    }
    dexOptions {
        jumboMode true
        preDexLibraries = false
        // javaMaxHeapSize "4g"
    }
    configurations.all {
        resolutionStrategy {
            force 'com.android.support:design:28.0.0'
            force 'com.android.support:support-v4:28.0.0'
            // force 'com.google.android.gms:play-services-base:16.1.0'
            // force 'com.android.support:appcompat-v7:28.0.0'
        } 
    }
}

dependencies {
    implementation (project(':tipsi-stripe')){
        exclude group: 'com.google.android.gms'
        exclude group: 'com.google.firebase'
    }
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:support-v4:27.1.0"
    implementation "com.android.support:design:27.1.0"
    implementation "com.android.support:appcompat-v7:27.1.0"
    implementation "com.facebook.react:react-native:+"  // From node_modules

    // fbsdk
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'

    implementation project(':react-native-firebase')

    // firebase
    implementation "com.google.android.gms:play-services-base:16.1.0"
    implementation "com.google.firebase:firebase-core:16.0.9"

    // firebase messaging
    implementation "com.google.firebase:firebase-messaging:18.0.0"
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar' // <-- Add this line if you wish to use badge on Android

    // firebase crashlytic
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.9@aar') {
        transitive = true
    }

    if (enableHermes) {
        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'
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

apply plugin: 'com.google.gms.google-services'

android / build.gradle

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

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 22
        compileSdkVersion = 28
        targetSdkVersion = 28
        googlePlayServicesAuthVersion = "16.0.1" 
    }
    repositories {
        mavenCentral()
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.3")
        classpath("com.google.gms:google-services:4.3.3")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'io.fabric.tools:gradle:1.28.1'
    }
}

allprojects {
    repositories {
        mavenLocal()
        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")
        }
        maven { url "https://www.jitpack.io" }
        maven { url "https://maven.google.com" }
    }
}

ext {
    compileSdkVersion   = 28
    targetSdkVersion    = 28
    buildToolsVersion   = "28.0.3"
    supportLibVersion   = "28.0.0"
    googlePlayServicesVersion = "11.8.0"
    androidMapsUtilsVersion = "0.5+" 
}

MainApplication. java

import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

// codepush
import com.microsoft.codepush.react.CodePush;

// firebase
import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage;
import io.invertase.firebase.fabric.crashlytics.RNFirebaseCrashlyticsPackage;
import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;

// google sign-in
import co.apptailor.googlesignin.RNGoogleSigninPackage;

import com.gettipsi.stripe.StripeReactPackage;

import java.util.Arrays;
import java.util.List;
import android.content.Intent;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost =
      new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
          return BuildConfig.DEBUG;
        }

        @Override
        protected String getJSBundleFile() {
          return CodePush.getJSBundleFile();
        }

        @Override
        protected List<ReactPackage> getPackages() {
          @SuppressWarnings("UnnecessaryLocalVariable")
          List<ReactPackage> packages = new PackageList(this).getPackages();
          // Packages that cannot be autolinked yet can be added manually here, for example:
          // firebase
          // packages.add(new RNFirebasePackage());
          packages.add(new RNFirebaseMessagingPackage());
          packages.add(new RNFirebaseAnalyticsPackage());
          packages.add(new RNFirebaseNotificationsPackage());
          packages.add(new StripeReactPackage());
          return packages;
        }

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }
      };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    // initializeFlipper(this); // Remove this line if you don't want Flipper enabled
  }

  /**
   * Loads Flipper in React Native templates.
   *
   * @param context
   */
  private static void initializeFlipper(Context context) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */
        Class<?> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
        aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
}

response-native.config. js

module.exports = {
  dependencies: {
    'tipsi-stripe': {
      platforms: {
        android: null,
      },
    },
  },
};

settings.gradle

include ':tipsi-stripe'
project(':tipsi-stripe').projectDir = new File(rootProject.projectDir, '../node_modules/tipsi-stripe/android')
...