Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android wont build #289

Closed
gla5001 opened this issue Jan 23, 2019 · 4 comments
Closed

Android wont build #289

gla5001 opened this issue Jan 23, 2019 · 4 comments

Comments

@gla5001
Copy link

gla5001 commented Jan 23, 2019

This will not build with android using
compileSdkVersion 28
buildToolsVersion '28.0.3'
and
"react-native": "0.56.1"
"rn-fetch-blob": "^0.10.15"
The project seems to be linked correctly, but building on android produces the following failures

.../testapp/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java:9: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
                                 ^
.../testapp/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobFileResp.java:3: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
.../testapp/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java:3: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
.../testapp/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java:11: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
.../testapp/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobFileResp.java:80: error: cannot find symbol
        public long read(@NonNull Buffer sink, long byteCount) throws IOException {
                          ^
  symbol:   class NonNull
  location: class RNFetchBlobFileResp.ProgressReportingSource
.../testapp/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java:118: error: cannot find symbol
    public void writeTo(@NonNull BufferedSink sink) {
                         ^
  symbol:   class NonNull
  location: class RNFetchBlobBody
.../testapp/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java:112: error: cannot find symbol
            Uri uriForFile = FileProvider.getUriForFile(getCurrentActivity(),
                             ^
  symbol:   variable FileProvider
  location: class RNFetchBlob
.../testapp/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java:347: error: cannot find symbol
                public Response intercept(@NonNull Chain chain) throws IOException {
                                           ^
  symbol: class NonNull
.../testapp/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java:409: error: cannot find symbol
                public void onFailure(@NonNull Call call, IOException e) {
                                       ^
  symbol: class NonNull
.../testapp/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java:426: error: cannot find symbol
                public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
                                        ^
  symbol: class NonNull
.../testapp/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java:426: error: cannot find symbol
                public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
                                                            ^
  symbol: class NonNull
Note: .../testapp/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobUtils.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
11 errors

This is whats in my build.gradle

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

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 = false

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.mytest.app"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        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
            }
        }
    }
}

dependencies {
    implementation project(':rn-fetch-blob')
    api fileTree(dir: "libs", include: ["*.jar"])
    api "com.android.support:appcompat-v7:27.1.1"
    api "com.facebook.react:react-native:+"  // From node_modules
    api project(':libs:SalesforceReact') // From node_modules
}

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

I also have gradle.properties

android.useDeprecatedNdk=true
android.useAndroidX=true
android.enableJetifier=true
@gla5001 gla5001 closed this as completed Jan 24, 2019
@greg7gkb
Copy link

What was the resolution for this?

@gla5001
Copy link
Author

gla5001 commented May 11, 2019

@greg7gkb It’s an issue with AndroidX compatibility and the gradle deps. I have a PR up with fixes #291. But there’s been no movement on it.

I think your options are to either fork the repo and apply those changes or not enable AndroidX in your gradle properties (if that’s the issue you’re seeing)

@evan0204
Copy link

gradle.properties . add
android.useDeprecatedNdk=true android.useAndroidX=true android.enableJetifier=true

invalid

Is there any other way to solve it?

@MujtabaFR
Copy link

using Jetifier solved the issue for me

npm i -D jetifier
npx jetify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants