Michaelvilleneuve / react-native-document-scanner

Document scanner, features live border detection, perspective correction, image filters and more ! ๐Ÿ“ฒ๐Ÿ“ธ
MIT License
848 stars 290 forks source link

react-native-document-scanner not build for android #62

Open umutcetinkaya opened 5 years ago

umutcetinkaya commented 5 years ago

Does anyone have an idea ?

run : react-native run-android

result :

BUILD FAILED in 6s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 /Users/workpc/Projects//android/app/src/main/java/com/isegeldim/MainApplication.java:10: error: cannot find symbol import org.opencv.DocumentScannerPackage; ^ symbol: class DocumentScannerPackage location: package org.opencv /Users/workpc/Projects//android/app/src/main/java/com/isegeldim/MainApplication.java:16: error: package com.reactlibrary does not exist import com.reactlibrary.RNPdfScannerPackage; ^ /Users/workpc/Projects//android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:27: error: cannot find symbol import org.opencv.DocumentScannerPackage; ^ symbol: class DocumentScannerPackage location: package org.opencv /Users/workpc/Projects//android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:86: error: cannot find symbol new DocumentScannerPackage(), ^ symbol: class DocumentScannerPackage location: class PackageList 4 errors

FAILURE: Build failed with an exception.

BUILD FAILED in 6s

at checkExecSyncError (child_process.js:591:13)
at execFileSync (child_process.js:611:13)
at runOnAllDevices (/Users/workpc/Projects/***/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:74:39)
at buildAndRun (/Users/workpc/Projects/***/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:158:41)
at then.result (/Users/workpc/Projects/***/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:125:12)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
jorgemasta commented 5 years ago

Duplicated https://github.com/Michaelvilleneuve/react-native-document-scanner/issues/52

Basically, change import org.opencv.DocumentScannerPackage; to import com.documentscanner.DocumentScannerPackage in MainApplication.java

umutcetinkaya commented 5 years ago

@jorgemarrero I'm having the same problem. I made the change as you said, but the problem was not solved?

jorgemasta commented 5 years ago

Have you follow https://github.com/Michaelvilleneuve/react-native-document-scanner#android-only ?

umutcetinkaya commented 5 years ago

@jorgemarrero Yes, I did it all step by step. But it didn't. :(

umutcetinkaya commented 5 years ago

Task :app:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings 185 actionable tasks: 31 executed, 154 up-to-date /Users/workpc/Projects/projectname/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:27: error: cannot find symbol import org.opencv.DocumentScannerPackage; ^ symbol: class DocumentScannerPackage location: package org.opencv /Users/workpc/Projects/projectname/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:86: error: cannot find symbol new DocumentScannerPackage(), ^ symbol: class DocumentScannerPackage location: class PackageList 2 errors

FAILURE: Build failed with an exception.

BUILD FAILED in 8s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 /Users/workpc/Projects/projectname/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:27: error: cannot find symbol import org.opencv.DocumentScannerPackage; ^ symbol: class DocumentScannerPackage location: package org.opencv /Users/workpc/Projects/projectname/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:86: error: cannot find symbol new DocumentScannerPackage(), ^ symbol: class DocumentScannerPackage location: class PackageList 2 errors

FAILURE: Build failed with an exception.

BUILD FAILED in 8s

at checkExecSyncError (child_process.js:591:13)
at execFileSync (child_process.js:611:13)
at runOnAllDevices (/Users/workpc/Projects/projectname/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:74:39)
at buildAndRun (/Users/workpc/Projects/projectname/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:158:41)
at then.result (/Users/workpc/Projects/projectname/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:125:12)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
jorgemasta commented 5 years ago

This could be related to this issue #56 ๐Ÿค”

I am actually using my own fork of this package https://github.com/Woonivers/react-native-document-scanner

You can try it: yarn add @woonivers/react-native-document-scanner but you will need to change all from react-native-document-scanner to @woonivers/react-native-document-scanner in your project.

This package has done a great job, but I feel it is not maintained.

umutcetinkaya commented 5 years ago

@jorgemarrero your react-native version ?

jorgemasta commented 5 years ago

@jorgemarrero your react-native version ?

0.59.9

umutcetinkaya commented 5 years ago

I am using version 0.60. Would you mind if I went to the repo you called? @jorgemarrero

jorgemasta commented 5 years ago

Ahรก, probably that's the problem. 0.60 changes a lot in Android, I haven't update for that reason :(

umutcetinkaya commented 5 years ago

@jorgemarrero What can you do to make it run at 0.60.xx ? do you have an idea ?

jorgemasta commented 5 years ago

@jorgemarrero What can you do to make it run at 0.60.xx ? do you have an idea ?

No idea, I'm sorry ๐Ÿ˜Ÿ I will face that problem in the next few weeks/months.

The android part is very inspired by this repository https://github.com/ctodobom/OpenNoteScanner, maybe you can find some solution based on that.

jorgemasta commented 5 years ago

Hi @umutcetinkaya , I have updated my fork to work with react-native 0.60+

haneul512 commented 5 years ago

hello @jorgemarrero. Trying to get it to compile, but getting

PackageList.java:17: error: cannot find symbol import org.opencv.DocumentScannerPackage;

I'm using 0.61.1. Any idea?

jorgemasta commented 5 years ago

hello @jorgemarrero. Trying to get it to compile, but getting

PackageList.java:17: error: cannot find symbol import org.opencv.DocumentScannerPackage;

I'm using 0.61.1. Any idea?

What's version are you using?

haneul512 commented 5 years ago

@jorgemarrero I have cloned your master (2.0.0 I suppose) and trying to run it from example folder

jorgemasta commented 5 years ago

@jorgemarrero I have cloned your master (2.0.0 I suppose) and trying to run it from example folder

Sorry, the example folder was pointing to the previous version. I am working on make that dynamically, but I am having issues with auto-linking. I have updated master with that change.

umutcetinkaya commented 5 years ago

@jorgemarrero Did you know that you are running over 0.60 where you are currently forking?

ntvinhit commented 4 years ago

hello @jorgemarrero. Trying to get it to compile, but getting

PackageList.java:17: error: cannot find symbol import org.opencv.DocumentScannerPackage;

I'm using 0.61.1. Any idea?

You should disable auto link in RN 0.60+ Edit / Create react-native.config.js

module.exports = {
  dependencies: {
    'react-native-document-scanner': {
      platforms: {
        android: null
      }
    }
  }
};
Gricardov commented 4 years ago

This could be related to this issue #56 ๐Ÿค”

I am actually using my own fork of this package https://github.com/Woonivers/react-native-document-scanner

You can try it: yarn add @woonivers/react-native-document-scanner but you will need to change all from react-native-document-scanner to @woonivers/react-native-document-scanner in your project.

This package has done a great job, but I feel it is not maintained.

Chamo, a ti te ha funcionado este repo con RN 0.60 ?

Yangeok commented 4 years ago

@Gricardov Is @woonivers/react-native-document-scanner working for both Android and iOS?

hegdeMadan commented 4 years ago

same issue for me as well. Anyone found the fix???

alessandrots commented 4 years ago

This repo @woonivers/react-native-document-scanner is great. Work on react-native > 0.6.0.

However, important things like detectedRectangle doesn't work on Android, only on IOS. In my case it is very important to me.

obertil commented 4 years ago

After 2 long days of work, I finally succeeded to make it work. Here is what I've done, inspired by the previous comments and this issue on react-native-splash-screen

Install

$ yarn add https://github.com/Michaelvilleneuve/react-native-document-scanner

Link manually for android First, we will disable autolink on android , so Edit / Create react-native.config.js at the root of your project

module.exports = {
  dependencies: {
    'react-native-document-scanner': {
      platforms: {
        android: null
      }
    }
  }
};

Now link manually react-native-document-scanner and openCV in your settings.gradle file

include ':react-native-document-scanner'
project(':react-native-document-scanner').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-document-scanner/android')

include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-document-scanner/android/openCVLibrary310')

In android/app/src/main/java/com/your/project/MainActivity.java add

import com.documentscanner.DocumentScannerPackage;

In android/app/src/main/java/com/your/project/MainApplication.java add

import com.documentscanner.DocumentScannerPackage;

In android/app/build.gradle add

dependencies {
    [...]
    compile project(':react-native-document-scanner')
}

The process already described in the readme for iOS works correctly for me.

dheerajk27 commented 4 years ago

After 2 long days of work, I finally succeeded to make it work. Here is what I've done, inspired by the previous comments and this issue on react-native-splash-screen

Install

$ yarn add https://github.com/Michaelvilleneuve/react-native-document-scanner

Link manually for android First, we will disable autolink on android , so Edit / Create react-native.config.js at the root of your project

module.exports = {
  dependencies: {
    'react-native-document-scanner': {
      platforms: {
        android: null
      }
    }
  }
};

Now link manually react-native-document-scanner and openCV in your settings.gradle file

include ':react-native-document-scanner'
project(':react-native-document-scanner').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-document-scanner/android')

include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-document-scanner/android/openCVLibrary310')

In android/app/src/main/java/com/your/project/MainActivity.java add

import com.documentscanner.DocumentScannerPackage;

In android/app/src/main/java/com/your/project/MainApplication.java add

import com.documentscanner.DocumentScannerPackage;

In android/app/build.gradle add

dependencies {
    [...]
    compile project(':react-native-document-scanner')
}

The process already described in the readme for iOS works correctly for me.

@obertil Followed your steps (thanks for the same!) for Android and then, it's building without issue. Though, while running the app on android device, I am getting the error "RNPdfScanner was not found in the UIManager". Repeated the steps, but still encountering this issue on Android. On iOS, facing no issues...

May be you forgot to mention some step here?

SiSa68 commented 4 years ago

@obertil Thanks for your solution It works for me, with react-native v0.63.3 I've also upgrade the gradle version for the library as below

For ./node_modules/react-native-document-scanner/android/build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
    }
}

android {
    compileSdkVersion safeExtGet('compileSdkVersion', 29)
    buildToolsVersion safeExtGet('buildToolsVersion', '29.0.2')
    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 16)
        targetSdkVersion safeExtGet('targetSdkVersion', 29)
    }
}

For ./node_modules/react-native-document-scanner/android/openCVLibrary310/build.gradle

android {
    compileSdkVersion 29
    ...
}

And for ./node_modules/react-native-document-scanner/android/gradle/wrapper/gradle-wrapper.properties

...
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip

And a missing step in android/app/src/main/java/com/your/project/MainApplication.java We should add DocumentScannerPackage to our packages in getPackages function:

    @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:
        packages.add(new DocumentScannerPackage());
        return packages;
    }
skv-headless commented 3 years ago

in react-native.config.js

dependencies: {
        'react-native-document-scanner': {
            platforms: {
                "android": {
                    "packageImportPath": "import com.documentscanner.DocumentScannerPackage;",
                    "packageInstance": "new DocumentScannerPackage()"
                }
            }
        },
        "react-native-perspective-image-cropper": {
            platforms: {
                "android": {
                    "packageImportPath": "import fr.michaelvilleneuve.customcrop.RNCustomCropPackage;",
                    "packageInstance": "new RNCustomCropPackage()"
                }
            }
        }
    }

Hope it will be in repo one day ๐Ÿ˜ž

laibulle commented 3 years ago

@skv-headless You saved my day thanks a lot.

Gricardov commented 3 years ago

Too late for me, I already migrated to Flutter due to this. But thanks chamo! <3

AlenToma commented 3 years ago

You dont need to disable link you only need to add the line below to setting.grade

include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/@woonivers/react-native-document-scanner/android/openCVLibrary310')

auto link should know that openCVLibrary310 has already been linked and will only add the code to .java

joy-mollick commented 3 years ago

This package isn't build for android , wasting so much time over this.

sadeghhosseini commented 2 years ago

, "react-native-perspective-image-cropper": { platforms: { "android": { "packageImportPath": "import fr.michaelvilleneuve.customcrop.RNCustomCropPackage;", "packageInstance": "new RNCustomCropPackage()" } } }

Hi, thanks for the answer. Where should I be putting this? In my project or in the library?

The format you have specified caused an error while running react-native run-android, so I did this:

module.exports = {
    dependency: {
        platforms: {
            // iOS specific properties go here
            ios: {},
            // Android specific properties go here
            android: {
                'react-native-document-scanner': {
                    "packageImportPath": "import com.documentscanner.DocumentScannerPackage;",
                    "packageInstance": "new DocumentScannerPackage()"
                },
                "react-native-perspective-image-cropper": {
                    "packageImportPath": "import fr.michaelvilleneuve.customcrop.RNCustomCropPackage;",
                    "packageInstance": "new RNCustomCropPackage()"
                }
            },
        },
    },
};

Yet I still get the same error. I would really appreciate your help.