ZXing imports disappearing - android

I am trying to install zxing in android studio but i am running into some trouble. I have looked around at lots of different posts and tutorials and they have all said to just add the following lines into the build.gradle dependencies
compile 'com.google.zxing:core:3.1.0'
compile 'com.google.zxing:android-integration:3.1.0'
I have done this and synced everything but when I try and add an import like
import com.google.zxing.integration.android.IntentResult;
at the top of my project it instantly disappears without an errors or warning.
Has anyone else had this problem or know what I am doing wrong?

Your IDE will remove the import if you have some auto-cleaning unused import statements. It depends on the IDE to configure this option but both Android Studio and Eclipse have this feature.
I suggest you to start using this IntentResult and then it will keep the import statement.

Related

Android Studio does not rearrange import in lexicographic order

Given the following imports
import javax.inject.Inject
import kotlinx.android.synthetic.main.fragment.*
Android Studio rearrange to the following when pressing control + option + o
import kotlinx.android.synthetic.main.fragment.*
import javax.inject.Inject
Which is not in lexicographic order. My pre-commit hook running ktlint then fails because of this. Is there any way to fix this issue?
Its strange behavior but if you delete all from Import aliases separately you will get lexicographical order
Before:
After:
The latest IntelliJ IDEA / Android Studio might not be able to conform to full specifications in the Android Kotlin style guide. So, currently, there is no straight-forward way of arranging the imports lexicographic order in IntelliJ IDEA / Android Studio.
For now, you may want to disable this check for Klint by disabling 'import ordering' in the .editorconfig file in the root of your project:
[*.{kt,kts}]
disabled_rules = import-ordering
This will disable the check in your project.
IntelliJ IDEA / Android Studio doesn't let you order imports alphabetically, neither in Java nor in Kotlin.
However Java features an Import layout section, which can give you some control. But still it's impossible to have an exact ordering, as you want it.
This isn't available for Kotlin is now available in Kotlin too. You can look at https://youtrack.jetbrains.com/issue/KT-10974
You could disable import ordering for that file.
I had this:
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import java.io.Serializable
import kotlinx.android.parcel.Parcelize
Ktlint reordered it that way, but check continued to fail:
Had to add the ignore in the first line:
import android.os.Parcelable // ktlint-disable import-ordering
import com.google.gson.annotations.SerializedName
import java.io.Serializable
import kotlinx.android.parcel.Parcelize
If you are in IntelliJ/Android Studio, usually just clicking Code -> Optimize Imports is enough to fix it
That’s just a linting error if I recall correctly
I know this is old, and I did manage to fix the issue by adding // ktlint-disable import-ordering but eventually I found a better solution.
If you have command line ktlint installed, you can run the ktlint --android -F terminal command on your android source code folder and it will automatically fix this issue. The --android part is very important, using the ktlint -F command, without the android part, will fix some ktlint issues but not his one.
You can run this command on your android studio terminal. This will automatically reformat all the ktlint issues.
Cmd -
./gradlew ktlintFormat
I ran into a rare case where my android project was using ktlint v0.47.1. Everything passed when I ran the command ./gradlew ktlint locally; and ./gradlew ktlintFormat didn't find anything to change.
However, it kept failling the lint checks with the PR because it was using the latest version v0.48.2 in the Github action setup. There are fixes for importing in v0.48.
I updated ktlint to v0.48.2 in the project in order to find and fix the lexicographic order issues.

React Native app works on Android with import errors

My React Native app works with import errors. I have done everything needed to fix the errors, although Android Studio still says there are errors, even though my app builds and runs successfully.
Does anyone know how to remove these false errors?
Import errors created by gradle default usually, please check your gradle.build.
Make sure you have
On some cases, you manually import the files, so check the files if you manual import the files to your project.
Maybe you need to see this tutorial to setup your gradle:
https://facebook.github.io/react-native/docs/building-from-source
Thanks.

Flutter Android Support Library Not Recognized

I am writing a Flutter wallpaper app and am calling Android Specific code and I need to ask the user for some permissions, I need to import ContextCompat for that but there is not option to import in the quick menu, so I read online and manually did it.
import android.support.v4.content.ContextCompat
The problem is that Android Studio can't resolve the support symbol, I also read some forums online about that as well. The most common answer I found was to include add the android support library in the Gradle, which I have already tried but did not work.
Any help would be dearly appreciated.
com.android.support:appcompat-v7 should automatically take care of the dependency of ContextCompat
e.g. adding following in the dependency -
implementation 'com.android.support:appcompat-v7:26.1.0'
Here the version 26.1.0 would depend on your compile version.

FirebaseJobDispacher package not being added to my project after syncing gradle

I am following a Google's tutorial and I've added the following to my project:
compile 'com.firebase:firebase-jobdispatcher:0.8.5'
But when I attempt to import anything from this package, it's like it wasn't even compiled/implemented at all. I tried rebuilding and cleaning the project, erasing the line in gradle, syncing, adding it to gradle again and syncing again but nothing changes.
According to the tutorial, the Driver class belongs to com.firebase.jobscheduler.Driver, but as shown in the image, it isn't there.
Did I forget something? I saw no different action to import this package.

Facebook SDK / Parse SDK on Android Studio "cannot resolve symbol R"

I am trying to configure my app with Facebook and Parse. I followed all their instructions and copied/edited the sample code accordingly.
Finally, I was met with this error:
the import tags
ex.
import com.facebook.FacebookRequestError;
import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
etc.
were underlined red, and there were plenty of errors in the project. i clicked the little red bulb above these tags and added the facebook dependency. this got rid of most of the errors and imported the above. however, a new issue was introduced: everything in the project that has: "R.whatever" has the R underlined.
How do I fix this?
Also, if this helps, the userdetails.xml has a rendering issue saying the following:
endering Problems NOTE: This project contains Java compilation errors, which can cause rendering failures for custom views. Fix compilation problems first. The following classes could not be found:
- com.facebook.widget.ProfilePictureView
EDIT
I am using Android Studio
Are you using Eclipse? The missing R errors usually are a resault of a compilation error. Try to first run the clean command on the project and compile it again, and if that doesn't help look for any errors apart from the missing R - you should be able to find one that's different and it's probably causing the problem.

Categories

Resources