首页 > 解决方案 > “无法调用 WifiManager.connectToProtectedSSID”仅在应用程序基于 bitrise 而不是本地计算机构建时发生

问题描述

我开发了一个用 react native 编写并使用 react-native-wifi-reborn 连接 Wi-Fi 的 IoT 应用程序,该应用程序无法连接 Wi-Fi 并出现以下错误(仅在 Android 中。iOS 未显示任何日志)突然从 11 月 17 日开始。

Could not invoke WifiManager.connectToProtectedSSID  

null

Failed resolution of: Lcom/thanosfisherman/elvis/Elvis;

Didn't find class "com.thanosfisherman.elvis.Elvis" on path: DexPathList[[zip file "XXX"...

实际上,该应用程序已经发布了很多次,并没有改变任何工作流程和依赖关系。
我发现了同样的问题,但它对我没有帮助......
https://github.com/JuanSeBestia/react-native-wifi-reborn/pull/117

我做了

所以我将分享bitrise的workflow.yml、package.json和build.gradle的一部分。

workflow.yml

workflows:
  _setup:
    steps:
    - activate-ssh-key@4.0.3:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@4.0.17:
        inputs:
        - update_submodules: 'no'
    - cache-pull@2.1.0: {}
    - npm@1.1.1:
        inputs:
        - command: install
    - install-missing-android-tools@2.3.7:
        inputs:
        - gradlew_path: "$PROJECT_LOCATION/gradlew"
    - script@1.1.5:
        title: Do anything with Script step
        inputs:
        - content: |-
            #!/usr/bin/env bash
            set -e
            set -x

            git checkout . && npm i -g jetifier && npx jetify
            echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system
            npm install -g react-native-cli
            node --version
            node --max_old_space_size=4096 --expose-gc --inspect /usr/lib/node_modules/react-native-cli/index.js bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
    - generate-gradle-wrapper@0.9.2:
        inputs:
        - project_root_dir: "$BITRISE_SOURCE_DIR/android"
  dev_deploy_gate:
    before_run:
    - _setup
    - _set_version
    after_run:
    - _teardown
    steps:
    - gradle-runner@1.9.1:
        inputs:
        - gradle_task: assembleDebug --info
        - gradle_file: "./android/build.gradle"
        - gradle_options: --stacktrace --no-daemon -Dorg.gradle.jvmargs="-Xmx4096m
            -XX:+HeapDumpOnOutOfMemoryError"
        - gradlew_path: "./android/gradlew"
    - sign-apk@1.4.1:
        inputs:
        - output_name: app-debug.apk
        - android_app: "./android/app/build/outputs/apk/debug/app-debug.apk"
    - deploygate--upload-app-bitrise-step@1.0.1:
        inputs:
        - owner_name: XXX
        - app_path: "./android/app/build/outputs/apk/debug/app-debug.apk"
        - message: 'Upload from Bitrise. Build Number: $BITRISE_BUILD_NUMBER, $GIT_CLONE_COMMIT_MESSAGE_SUBJECT'
        - distribution_name: "$BITRISE_GIT_BRANCH"
        - release_note: 'Upload from Bitrise. Build Number: $BITRISE_BUILD_NUMBER,
            $GIT_CLONE_COMMIT_MESSAGE_SUBJECT'
        - api_key: "$DEPLOYGATE_APIKEY"
        is_always_run: true

package.json

"dependencies": {
    "@hawkingnetwork/react-native-tcp": "^3.3.2",
    "@react-native-community/geolocation": "^2.0.2",
    "@react-native-community/netinfo": "^5.9.6",
    "@react-navigation/native": "^5.7.3",
    "@react-navigation/stack": "^5.9.0",
    "@sentry/react-native": "^1.6.3",
    "@types/node": "^14.0.24",
    "react": "16.13.1",
    "react-native": "^0.63.2",
    "react-native-android-location-enabler": "^1.2.1",
    "react-native-background-fetch": "^3.1.0",
    "react-native-background-geolocation": "^3.8.1",
    "react-native-background-timer": "^2.3.1",
    "react-native-ble-manager": "^7.2.0",
    "react-native-camera": "^3.33.0",
    "react-native-firebase": "^5.6.0",
    "react-native-gesture-handler": "^1.7.0",
    "react-native-haptic-feedback": "^1.10.0",
    "react-native-keychain": "^6.2.0",
    "react-native-permissions": "^2.1.5",
    "react-native-power-saving-mode": "^0.1.1",
    "react-native-progress": "^4.1.2",
    "react-native-prompt-android": "^1.1.0",
    "react-native-reanimated": "^1.10.1",
    "react-native-share": "^3.7.0",
    "react-native-tcp-socket": "^4.2.0",
    "react-native-v8": "^0.63.2-patch.0",
    "react-native-vector-icons": "^7.0.0",
    "react-native-wifi-reborn": "^4.3.3",
    "react-navigation": "^4.4.0",
    "react-navigation-stack": "^2.8.2",
    "react-redux": "^7.1.1",
    "redux": "^4.0.4",
}

app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'deploygate'

import com.android.build.OutputFile

project.ext.react = [
        entryFile: 'index.js',
        enableHermes: false,  // clean and rebuild if changing
        enableV8: true,  // clean and rebuild if changing
]

apply from: '../../node_modules/react-native/react.gradle'
apply from: '../../node_modules/@sentry/react-native/sentry.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 = false

/**
 * The preferred build flavor of JavaScriptCore.
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US.  Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
def enableHermes = project.ext.react.get('enableHermes', false)

/**
 * Whether to enable the Google V8 Engine.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to V8 Code
 * and the benefits of using V8 will therefore be sharply reduced.
 */
def enableV8 = project.ext.react.get('enableV8', false)

/**
 * Background geolocation project object.
 *
 * This object is having project details of background geolocation object
 */
Project background_geolocation = project(':react-native-background-geolocation')

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId 'app.jp.co.XXX'
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 73
        versionName '1.8.0'
        missingDimensionStrategy 'react-native-camera', 'general'
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }
    splits {
        abi {
      reset()
      enable enableSeparateBuildPerCPUArchitecture
      universalApk false  // If true, also generate a universal APK
      include 'armeabi-v7a', 'x86', 'arm64-v8a', 'x86_64'
        }
    }
    signingConfigs {
        debug {
      storeFile file('debug.keystore')
      storePassword 'android'
      keyAlias 'androiddebugkey'
      keyPassword 'android'
        }
    }
    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.debug
      proguardFiles "${background_geolocation.projectDir}/proguard-rules.pro"
      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 {
    javaMaxHeapSize '3g'
    }

    packagingOptions {
    //Make sure libjsc.so does not packed in APK for v8
    exclude '**/libjsc.so'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    // From node_modules
    implementation 'no.nordicsemi.android:dfu:1.8.1'
    implementation 'com.deploygate:sdk:4.1.0'

    implementation 'com.google.android.gms:play-services-base:17.3.0'
    implementation 'com.google.firebase:firebase-core:17.4.4'
    implementation 'com.google.firebase:firebase-auth:19.3.2'
    implementation 'com.google.firebase:firebase-storage:19.1.1'
    implementation 'com.google.firebase:firebase-firestore:21.5.0'
    implementation 'com.google.firebase:firebase-functions:19.0.2'
    implementation 'com.google.firebase:firebase-messaging:20.2.3'
    implementation 'com.google.firebase:firebase-invites:17.0.0'

  if (enableHermes) {
    def hermesPath = '../../node_modules/hermes-engine/android/'
    debugImplementation files(hermesPath + 'hermes-debug.aar')
    releaseImplementation files(hermesPath + 'hermes-release.aar')
    } else {
    if (enableV8) {
      implementation 'org.chromium:v8-android:+'
        } 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 from: file('../../node_modules/react-native-vector-icons/fonts.gradle')
apply from: "${background_geolocation.projectDir}/app.gradle"
apply plugin: 'com.google.gms.google-services'

有人解决了这个问题吗?

标签: react-nativereact-native-androidbitrise

解决方案


推荐阅读