Removing referenced libraries from project Android Studio - android

I am trying to get Android Studio to work with library dependencies for my project, I am using Android Studio 0.4.0.
I've removed the dependecies from the project structure dialogue, from the settings.gradle and from the build.gradle and also from my project.iml file.
I then delete the directories of the referenced libraries from my main project, but after a few seconds, the referenced library directory reappears but only contains mylibrary.iml file. Everytime I delete it, it reappears again.
Also when Android Studio loads it displays an error stating that non gradle projects can't be referenced from gradle projects but I no longer want them referenced but somehow I can't get rid of them.
The project was imported into Android Studio from an Export from Eclipse.
Thanks for any help you can provide.

Generally, clicking on the Sync Project with Gradle Files button should clear up problems, but if they persist, you can close Android Studio, delete all the .idea folders and .iml files in your project and re-import.

There is an official bug on improving this for Android Studio. It includes a bigger description of the problem and a workaround suggested by one of the Android Studio engineers:
Bug description - click on the star button to follow it:
https://code.google.com/p/android/issues/detail?id=61510
Google Engineer suggested workaround (note that some of the bugs described are fixed):
https://code.google.com/p/android/issues/detail?id=61510#c3

Related

Using library in Android Studio - empty classes.jar

I added the following dependency to to build.gradle file in Android Studio and resync-ed the project successfully:
compile 'se.emilsjolander:stickylistheaders:2.1.3'
However I was unable to use any of the class in this library. Feeling strange I opened the source tree and see if there's anything wrong. I noticed the following:
You can see Android Studio can found the available classes for other downloaded archives, but not the one I mentioned in this question. The classes.jar file is reported empty.
I tried adding an older version of the stickylistheaders library (2.1.3). Still an empty classes.jar.
When I start this question I found a similar post here. But the author of that post tried to include the downloaded project in settings.gradle, and he finally managed to include the library through the "compile" directive. My problem is that I AM using the "compile" directive, but the downloaded archive has a "empty" classes.jar. I also tried adding the library mentioned in that question (i.e. 'se.emilsjolander:StickyScrollViewItems:1.0.0'). Also an empty classes.jar.
Some notes:
The actual classes.jar file found in build/exploded-bundles is not empty.
I tried cleaning the project. I suppose this will cause all dependencies be removed and re-downloaded. However, after that, Android Studio still cannot spot any class in stickylistheaders' classes.jar.
So far, this problem only exists for se.emilsjolander's libraries. Strangely, the answerer of this post1 posted a screenshot showing that he does see a non-empty classes.jar.
Update:
I also tried deleting .gradle's cache directory in my profile directory, clean the project and rebuild again. No luck.
I can unzip the classes.jar in question. Looks like the file isn't corrupt.
Anyone knows what's wrong here? Thanks.
I think I have found the cause: it should be a bug in Android Studio.
https://code.google.com/p/android/issues/detail?id=64008
In fact, the code can build and run despite seeing errors in Android Studio. So it is obviously an issue with Android Studio.
Update 27 Jan: It should have been resolved in Android 0.4.3. As from the release notes:
Fixed a bug around library syncing (where library dependency classes
and resources could suddenly not be found by the IDE)
Have you tried syncing your project with Gradle?
Tools -> Android -> Sync project with Gradle Files.
That should reload the build.gradle file and download the (missing) dependencies.
Try this once and make sure you are not getting any error in project Structure saying that "your_lib_name not used/added"
Open File > Project Structure
and check for erros. If error is shown click on it , it will expend the errors and will show some options on right, click on the Red bulb and choose "Add to dependency".
This seems be a bug in Studio which will be fixed in next release(Android Studio 0.4.3).

Duplicate files in Android Studio project view

I have a strange issue where project specific root level files (.gitignore, gradlew, gradle.properties, etc) show up twice in Android Studio's project view. Does anybody know how to fix this?
I've tried re-importing the project (after deleting the .iml and .idea file/folder).
I found exactly the same problem recently when I created a new Gradle project and imported into IntelliJ. However, the root cause seems to be the use of symbolic links when importing the project.
I have the following symbolic link:
/data -> /Users/<user>/data
When I originally imported my project, I imported /data/checkouts/<project_dir> but found that I had duplicate files from the top level directory exactly like as shown above.
However, I removed the project and attempted to import it again, this time using the full path of /Users/<user>/data/checkouts/<project_dir> and found that I no longer see the duplicates.
I haven't seen this problem before when importing an eclipse or Maven project, so can only imagine that it might be related to the use of the Gradle plugin for IntelliJ.

Android Studio Marks syntax as error, but gradle compiles

I have a project in Android Studio which compiles with Gradle.
The general file structure is
MyProject
- MyProjectSource
- Libraries
- ActionBarSherlock
My project is built with Gradle and will compile without issue. However in the lines within my activity where I include a component from ActionBarSherlock, Android Studio marks it as an error.
I have noticed that Android Studio has also generated .iml files. So my question: Does Android Studio ignore the gradle build when assessing whether something is valid syntax or not?
Obviously this is not a project blocking problem but it does slow velocity not being able to take advantage of the full set of tools Android Studio has to offer.
Thanks in advance for any help.
These are not errors actually, this a bug in Android studio( 0.4.2 ) for resolving the symbol and fixed for the next release( 0.4.3 ).
To get Rid of these until the release do the following
Clean your project using Build > Clean Project
Close your Android Studio
Take Backup of your project
Delete all .iml files inside your project
Delete content of .idea directory
Open Studio and wait until it completes the sync with gradle
Also verify if you are seeing any error in File > Project Structure . If there is any error saying "Dependency Not Added "click on that and using red bulb on right side Add them to dependency.
UPDATE
Android Studio 0.4.3 is available on Canary Channel Now.
UPDATE: #laochiv, I have found that cleaning manually the folder .idea/libraries and clicking afterward on "Sync Project with Gradle Files" solves the problem. Apparently this Sync does not remove elements, but keep the old ones and add the current ones. Probably a bug to report :)
I am having the same problem. However, I am using ABS directly from Maven.
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
}
Even the ABS Gradle Sample application marks a syntax error, although it compiles.
However, in another computer everything is working perfectly. I can not think of different conditions in each scenario.
"Does Android Studio ignore the gradle build when assessing whether something is valid syntax or not?" Yes. Android Studio imports the project configuration but runs its own compiler as you are editing and saving (you can even change it to the Eclipse ECJ compiler). The true authority on the build is Gradle, and AS is still in beta. You can try to run the gradle resync or close and reimport the project. I have had to manipulate AS like this many times, especially after making edits to build.gradle.
Edit: I have found it better to use ActionBarSherlock as a gradle dependency rather than a library directory.
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
You will need to use the SDK manager and install the local maven repository.
But it is possible to eventually get rid of these compile errors, as long as your build.gradle doesn't create any extra sourceSets that AS doesn't understand; try not to deviate too much from the android gradle plugin examples.
Also, I've been running the Canary updates of AS for the latest and greatest.
I don't know how to add a library using MavenCentral. I follow these steps to include a library
Add library in App_Name/App_Name/libs folder.
In App_Name/build.gradle add this
dependencies {
compile ---
compile files('libs/fileName.jar') }
./gradlew clean
Make sure your Android studio is updated.
Go through the link and it worked for me.
1.) Choose File option from menu on left top side of android studio.
2.) Select the option : "Invalidate Cache/ Restart.." It will open an dialog.
3.) Click on the first button with option : "Invalidate and Restart"
4.) It will close the studio and restart it. Start indexing of the project.
It resolved my problem
Go to File -> Invalidate Cache/ Restart -> Invalidate and Restart
Source
https://www.youtube.com/watch?v=FX_gCTpqhwM
I had this problem in Android Studio 4.2, it might be fixed on 4.3
I have noticed that adding some dependencies did not attach the classes.jar to the dependency, so Gradle recognises everything but the IDE doesn't. To fix it:
Open Module Settings of your project
Select the dependency that has the error
Click Add (+) for that dependency (bottom of the pop up)
Navigate to your-project/build/exploded-bundles/your-dependency/classes.jar
The IDE should recognise the files now
Hope it helps
I had this today and gradle update/sync didn't solve. But updating to latest version of Android Studio 2.2 update 5 fixed (was on 2.1).
Here i'm talking about android studio version v3.1.2 where this same issue happened.In later android studio version(above 3.0.1) this issue again rises. So, I solved this by going through few things and here is how
Close android studio first
Navigate to your Project Folder
Delete .gradle and .idea folder (.gradle and .idea is hidden files. so make sure you tick Show Hidden Files in your File Explorer option to see these files
Open your project in android studio now
This Time another issue (unsupported module) will arise, but don't worry. I got you
Goto File in android studio and hit Sync Project with Gradle Files
Tada..! you're done now!
Simplest Solution
Comment/Remove the dependency which is showing syntax error & Sync Project.
Uncomment/Add again & Sync Project.
Yeah! error gone...
Before
After

Android Studio The project is already registered

I've a big problem with Android Studio.
I have a project that depends on two other projects (as libs).
I followed the guide Problems importing project into Android Studio regarding ActionBarSherlock for import external modules.
I opened "Project Structure", imported the module, but after that I can't see it in the Modules area.
The Modules area contains only the root module, seems it is not refreshed (this is strange). So if I try to add the module as a Dependency, Android Studio doesn't find any module!
Then, if I try to re-import the module, it says that the module/project is already registered!!
Maybe I'm missing something, but I don't know what....! I have this problem both on Windows and MacOSX.
Thanks in advance,
Federico
Look around in your .idea directory for mentions of the problematic project. I had the same problem and resolved it by deleting the entry from .idea/sbt.xml.
In ij go to menu: View -> Tool Windows-> Gradle
Right click on the problematic module and click Refresh External Project, You should see the module in project explorer.
I had a similar problem with ABS and other library imports. The 'Project Structure' interface just wouldn't show the modules. On trying to import the modules, it would prompt, "The project is already registered". Seems to be an IntelliJ/Android Studio issue. Invalidate Caches option didn't help.
Reimporting the project after some cleanup did work for me.
As a precaution, take a backup of your project and store it safely
Ensure that your project builds via gradle command-line and you have all required dependencies specified in respective build.gradle files. Try building with: gradle clean && gradle build
Close the project in Android Studio (or close Android Studio)
Delete .iml files and .idea folders from all modules and the main project
Start Android Studio and reimport the project (Import project from external model > Gradle)
you should remove the project from respective gradle/sbt/maven/ant tab (used to be on right vertical line of Android Studio/Intellij IDEA)
See this answer: https://stackoverflow.com/a/30442195/907576
My issue was fixed when I restart IDEA.

Cannot build library dependent project after update to ADT 14

In order to implement different versions of our UI we broke our program up into UI specific code and a common library project that has everything else. Up until yesterday when I updated to ADT 14 everything was working fine. Now I can't build. I keep getting the error "The container 'Library Projects' references non existing library 'path to the bin folder of my common project and the name of the project.jar'
I've been all over the web and tried everything I can think of to fix this to no avail. Can someone help me out? I'm basically stuck at this point.
Maybe you have the same issues I had when switching to the new ADT:
In my previous setup I had some resources split between the library and the main project. The library project would not compile error free on its own but only in combination with the main project which added the missing resources.
It doesn't work like this any more.
The library project must compile completely error free now. When it does the build process will create a <lib_project_name>.jar in the bin folder of the library project.
If the jar file is not created ( thus the build process of the library project failed for some reason - eg. because the changes in the R.java file (see http://tools.android.com/recent/buildchangesinrevision14 )) you will get the error message you described.
Also, I had to manually remove the <lib_project>_src from the project.
I've had a problem with a few different projects where I did the fixes suggested in the other answer, but they were only fixed temporarily.
Every time I reopened Eclipse or did a Clean on a project, the "Library Projects" directory would disappear, and I would have to open the project properties, remove the library, and add it again.
I solved this the hard way by creating a new project and copying everything into it.
Then I found an easy way to solve it. Right click the project, Refactor-->Rename. You can rename it back afterwards. This fixed it.
Check out the article "Changes to Library Projects in Android SDK Tools, r14" ( http://android-developers.blogspot.com/2011/10/changes-to-library-projects-in-android.html ) on the Android Developers blog.
E.g. #P.Melch: "I had to manually remove the _src from the project" should be done as follows:
To fix the project, you must remove the extraneous source folders with the following steps:
Right click source folder and choose Build Path > Remove from Build
path.
A dialog will pop up. In it, make sure to check “Also unlink the folder from the project” to completely remove the folder.
You have to update the Android SDK in Android SDK Manager
Android SDK Tools Intalled
Android SDK Plataforms Installed
Android SDK Builds Installed

Categories

Resources