0

I'm trying to implement the code from answer #1 from this thread in Flutter.

The "invokeMethod" is correctly set and the Android gets correctly called. When I try to add the specific code that should come from the library "com.google.zxing", I don't understand how to import it.

I tried putting it into the Android gradle, but the zxing class methods remain "red" in MainActivity, as the library doesn't get imported.

Maybe there is a specific procedure to import external dependencies?

2 Answers 2

2

Apparently I had to import it this way in the class:

 import com.google.zxing.*;
 import com.google.zxing.common.*;

As the object "HybridBinarizer" is defined in the second one, and couldn't be retrieved otherwise.

As of the gradle, I had to add the dependency this way:

dependencies {

    classpath 'com.google.zxing:core:3.3.0'
}

in the file project/android/build.gradle, similar to the traditional Android way but using classpath instead of compile.

Another thing, a method of the zxing library (i.e. Result) was giving an error since the Result class was already defined in another library (io.flutter.plugin.common.MethodChannel.Result).

I solved this problem by creating a separate Java class and simply putting all the zxing methods there.

Sign up to request clarification or add additional context in comments.

Comments

0

if you're write a flutter plugin and want to add dependency to your android side you have to go to your build.gradle file and add dependencies block below the android block


android {

    compileSdkVersion 31

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion 16
    }
}

// you're dependencies block are here and put you're dependency inside it like you would in any normal android project

dependencies {
    // your dependency here
    implementation 'org.jsoup:jsoup:1.15.1'

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.