Importing code from github to Android Studio errors - android-studio

So I tried to import code from a github repository into Android Studio. I used VCS and everything went fine, no errors at all. But when I went to MainActivity.java it says cannot resolve symbol 'R' in this line setContentView(R.layout.activity_main);
I already checked the xml files and found no errors, as well as ran gradle cleans and builds. That didn't do it.
Thanks for your help.

So as you are saying, cleaning and rebuilding didn't help it. You might want to maybe upgrade/downgrade your gradle build version or try to copy it in again, since sometimes when copying errors occur for no outer reason.

Related

How to import android studio project from Github?

I am trying to import this project from github Kotlin-Bluetooth. Whenever I try to import the project I am met with a list of errors. Am I doing something wrong or is this normal?
I have been importing the file by hitting New>Project from Version Control... Then in the URL field I paste the following link: https://github.com/appsinthesky/Kotlin-Bluetooth.git. After this I am met with a list of errors. I have gone through trying to fix them one by one but it never stops. Am I importing the project incorrectly or do I need to continue trying to fix the errors?
Yes, your method is correct.
You should now try to resolve the errors.
Currently Android Studio has been upgraded a lot, projects created with Android Studio in previous versions are not compatible with the current version. So errors do occur, but they can be resolved.

Can't import android.app.Dialog after bad shutdown

I have custom class that extends android.app.Dialog, but after a bad pc shutdown when i was using android studio now i get: Cannot resolve symbol Dialog, with red.
You may say just don't use dialog and use AlertDialog instead, but the problem is even alert dialog is effected and i can't use .show() after creating it, i can only show dialog from builder instance (when i open AlertDialog class i can see app.Dialog also red).
The app run normally without any error even when android studio mark it with red and show no error during building.
All my project have the same problem so i though it's from the sdk.
I tried Clean rebuild, import project.
Tried invalidate cash and restart.
Remove .idea and iml.
I removed the entire sdk and re-downloaded.
I removed and re-downloaded .gradle file in User directory
I upgraded android studio version.
I changed buildToolsVersion and still it say Dialog class doesn't exist
When i open the sdk and go to android.app.dialog jar file i can see the dialog.java file there but android studio doesn't.
I can build i run the app without problem as i said but i can't keep seeing all those red marks in my files i hate that and i need solution.
Do i have to reinstall everything from sdk to android studio? or clean windows install?
Red Dialog import even when it exist in jar file
Can't use .show() method from AlertDialog instance
Okay so finally i deleted C:/users/username/.AndroidStudio3.6 folder with all files in it! Works like charm ! An stupid solution for a stupid problem, btw problem solved ! Thanks everyone !!😊😊

Cannot resolve symbol for my packages

Similar problems
Android Studio inline compiler showing red errors, but compilation with gradle works fine
Android Studio Marks syntax as error, but gradle compiles
My project broke after upgrading my Gradle version by editing build.gradle and gradle-wrapper.properties. However I can run it on virtual device without errors.
Neither Sync with Gradle files, Invalidate Caches nor rolling back to old commits solve the problem.
My workspace snapshot
Classes League and Match are in the same package but they can't see each other. Using classes with full path doesn't solve the issue, because my packages aren't visible e.g. Cannot resolve symbol 'model'. Also rolling back to previous commits doesn't fix the problem.
Initially I wanted to make New Relic work which required new version of gradle. This caused bigger problem. Can you help me find the solution?
EDIT
I think I figured it out. I created new project an copied only java source and xml res files from the old one and the red lines disappeared. Left screen is old project.
I had the same issue, and I still haven't figured out why it happened..
Anyways I resolved it by deleting the .idea folder and rebuilding the project from build.gradle.
Once you delete the .idea folder and restart Android Studio it will tell you it found an un-linked Gradle project (if you miss this message popup you can find it in the EventLog in the bottom right section), follow the directions to join the projects and it will fix itself.

Better to convert IntelliJ project to Gradle or to use Android Studio import project?

If you open an IntelliJ project in Android Studio, there is a warning that you should migrate to Gradle and it sends you to this link. This process seems a bit strange and complicating since the process is not well explained (it's more for experienced programmers who know how Gradle project looks like).
There is also a feature in Android Studio to import IntelliJ IDEA project. I did it with my project and it imported everything (except empty Proguard file), compiled well and all seems to work fine.
However, is this a valid process too - can I safely import future IDEA's project using import feature rather than the solution suggested by Android Studio?
Are there hidden dangers using this method? The least I would like it to continue coding newly imported Gradle-based project and at some point realize that the project is corrupted.
It should be fine. The projects it imports have their Gradle files properly set up, and if it works okay after import, there's nothing about the process by which it created that should make it stop working in the future. I think the link in that warning is just out of date.

Android Studio: disabling "External build" to display error output create duplicate class errors

I am starting my migration from Eclipse to Android Studio, and start playing with new projects on Studio.
My test project was working fine till I got some errors messages.
I had to do some manipulation (https://stackoverflow.com/a/16876993/327402) to enable the error output to display, and found the issue that I fixed.
Unfortunately, after this "workaround" (Why the hell have I to make such things to see my errors?), I found that there was an error message that I cannot fix:
error: duplicate class: com.mypackage.name.BuildConfig
error: duplicate class: com.mypackage.name.R
I also noticed that I am not the only one to have this issue (see the comment in the SO answer I linked above)
First time, I was able to fix it by enabling "External build" again, but that happened again, because I needed to see the error output and everything is now broken, and I cannot find what happen.
With Eclipse, the R file was easy to find, in the gen folder, but with Android Studio, there are too many files, and I am a little bit lost.
Any idea/suggestion?
I've found a question like this that has some replies here:
Cannot resolve R.java, duplicate class
You can try this:
Delete the Build folder generated by Android Studio automatically
Also you can try to Rebuild project by clicking Build->Rebuild project after deleting build folder.
So, just to let you know...
A few minutes after I posted my question, Google released an update to Android Studio (0.1.5)
See link: https://plus.google.com/+AndroidDevelopers/posts/Y9vhvGaHCbh
Tor Norbye kindly answered my question in this community, and I am sharing here
So the workaround I quoted in the OP is no more mandatory.
Enabling again External build after upgrading Android Sudio let me see the real errors ( a library and some Gradle import that I fixed)
So, I consider the Android Studio upgrade as the best answer to this question...
Ok, I also have the same problem, and this is what worked for me.
I first unticked external build from compiler settings. Then when I compiled i get two errors related to R.java, duplicate class.
Then i delete the build folder manually from finder. Then rebuild it from android studio, but still same error.
Then I again go back to compiler preference and tick the external build setting, and it worked fine after that.
Looks like some bug.
apparently, or at least for me 0.1.5 has a bug and cannot run in external build
because of some path error you can read about here
https://code.google.com/p/android/issues/detail?id=56628
so i switched to internal building, and then i hit the double R symbol bug
after deleting the build path application is compiled without errors but the build folder is not fully rebuilt, I'm missing the R.java file which the internal builder does not make.
i've rebuilt it on the external builder on an unupdated version as a temp workaround while this issues is fixed.
btw if anyone knows how to tell internal gradle to rebuild the build folder please share.
I just had the same problem and found a way to solve it (You can do this with Android Studio open):
Go to you Android Studio projects folder located in c:\users[USERNAME]\AndroidStudioProjects
Locate your project folder and open it.
Delete the folder named build.
From here, enter your application name folder, where you can find another build folder among with libs and src folders and a file named build.gradle.
RENAME the build folder to build2 or something else.
Now in Android Studio go to Build->Rebuild Project.
And after the project was rebuilt, open again the folder where the build2 folder that you renamed is located.
Delete the new folder named build that was created.
Rename your build2 folder to build again.
Done.

Resources