[JAVA] [Android] A story that stumbled when introducing ZXing, a QR code function library

Read the QR code using ZXing

This time, I will talk about a stumbling block when introducing the library in Android Studio. I wanted to implement it as the heading above. By the way, I'm a super beginner who started by installing Android Studio, so please take a look. The library introduced this time is a fairly famous library ** zxing **. When it comes to adding QR code functions in Android application development, there is a good chance that this library will be used. I will explain where I stumbled while actually explaining the introduction procedure. Publish your environment for the time being!

environment

AndroidStudioversion : 3.6.2 MinSDK : 26 buildtoolversion : 29.0.3 compileversion : 29 language : Koltin

Implementation

As for the state, create a new project and start from the state where nothing is touched. This one is easier to understand, and I don't like errors because of the setting of Iran. Well, I will do it.

Write directly in build.gradle to install the library.

Well, I was a super beginner, so I googled. As a result, it was said that the following code should be added to build.gradle, so I added it. By the way, this build.gradle is the one directly under the app directory.

build.gradle(app)


dependencies {
    //Other settings

    implementation 'com.journeyapps:zxing-android-embedded:4.1.0'
  //↑ Please use the latest version of the library at that time.
    
}

Yes. It was after this that I stumbled. On most sites, it's okay to add this sentence, but if you have some knowledge, you'll notice it here. Well, I'm a super beginner so I can't notice that. When I build it as it is and start it with the emulator, mysteriously, the application does not open (strictly speaking, it crashes at the moment of startup).

What's wrong?

So what's wrong? Of note is the language that builds this library. so. This library is built in Java. Therefore, it is okay to install the library, but it seems that the computer could not interpret it because it could not be compiled. Therefore, we need the ability to compile the language that builds this library. Now that you know the solution, let's try it.

Add to build.gradle (app) to resolve the error.

Just add a Java compiler to do this. Add the following code.

build.gradle(app)


android {
      //The initial settings are written
    compileOptions {
                sourceCompatibility JavaVersion.VERSION_1_8
                targetCompatibility JavaVersion.VERSION_1_8
                //↑ Maybe the latest version of this is also good
        }


After adding this, build it again and start it with the emulator .... Oh mysteriously it doesn't crash. Apparently the compiler was chased and the computer was able to recognize the library. (If you can't, check the space, unnecessary characters, and version.) With this, the introduction of this library was successful. After that, please add the reading etc. by yourself.

Finally

In this way, I learned that when introducing a library, it is necessary to pay attention to the construction language of the library. I'm a freshman in college, so I still don't have enough knowledge. I will introduce myself lightly.

The author is a college student. Yes. I'm an engineer with a part-time job. On Instagram, we mainly develop ios and android, disseminate information, notify posts of articles, useful information, and daily life, so please follow us if you like. Maybe follow back. I wish I could connect with many people. Account → ** taaa_kundayo ** URL:https://www.instagram.com/p/B-j3-RJjPWJ/?igshid=poq7k5z6eo3n

That's it for the article. Thank you very much! !!

Recommended Posts

[Android] A story that stumbled when introducing ZXing, a QR code function library
Thinking when introducing a new library
Java had a QR code creation library called QRGen that wrapped ZXing nicely, so I tried it.
A story that stumbled when deploying a web application created with Spring Boot to EC2