MaxToyberman / react-native-ssl-pinning

React Native ssl pinning and cookies handling based on okhttp3 on (Android). and AFNetworking on (iOS)
MIT License
346 stars 104 forks source link

Build failure (package android.support.annotation does not exist) #15

Closed mppperez closed 5 years ago

mppperez commented 5 years ago

Hello,

I've just started a new react native project from scratch and just added this library regarding to the readme. Unfortunately it won't build now anymore because of following error:

BUILD FAILED in 4s

Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
.../poc/node_modules/react-native-ssl-pinning/android/src/main/java/com/toyberman/RNSslPinningModule.java:3: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
.../poc/node_modules/react-native-ssl-pinning/android/src/main/java/com/toyberman/RNSslPinningModule.java:221: error: cannot find symbol
    @NonNull
     ^
  symbol:   class NonNull
  location: class RNSslPinningModule
Note: .../poc/node_modules/react-native-ssl-pinning/android/src/main/java/com/toyberman/Utils/OkHttpUtils.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

My package.json:

{
  "name": "poc",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "16.8.6",
    "react-native": "0.60.0",
    "react-native-ssl-pinning": "^1.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.5.4",
    "@babel/runtime": "^7.5.4",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.8.0",
    "eslint": "^6.0.1",
    "jest": "^24.8.0",
    "metro-react-native-babel-preset": "^0.55.0",
    "react-test-renderer": "16.8.6"
  },
  "jest": {
    "preset": "react-native"
  }
}

settings.gradle:

rootProject.name = 'poc'
include ':react-native-ssl-pinning'
project(':react-native-ssl-pinning').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-ssl-pinning/android')
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'

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 = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.1")

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

allprojects {
    repositories {
        mavenLocal()
        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")
        }

        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

My android/app/build.gradle is the default generated one as well. Just added the library depencdency declaration:

...
dependencies {
    implementation project(':react-native-ssl-pinning')
    ...
}

gradle.properties

android.useAndroidX=true
android.enableJetifier=true

I've found other threads with similar errors which suggested changing useAndroidX and enableJetifier to false: unfortunately this won't help here.

Any help is appreciated.

BR

mppperez commented 5 years ago

Ok, I've found a solution at StackOverflow: https://stackoverflow.com/a/56696796

npm install --save-dev jetifier (or use yarn, but install it locally in your project, not globally)
npx jetify or npx jetify -w=1 (to specify the number of parallel workers)

Kind of confusing since I expected "enableJetifier" should have done the same but it seems it doesn't