Problems importing project into Android Studio regarding ActionBarSherlock - java

Is anyone else having problems importing a project with ActionBarSherlock?
I have a total of 100 errors and 17 warnings. This worked perfectly in Eclipse. I followed the steps to create a Gradle build file. There were no import errors until I tried to build the Project.
I also tried re-downloading ABS fresh and replace into my project.
Were there known issues with ABS and IntelliJ? (which of course Android Studio is now based)
Here are a few errors I'm seeing:
java: ...
Workspace/ActionBarSherlock/src/com/actionbarsherlock/app/SherlockFragment.java:4: cannot find symbol
symbol : class Fragment
location: package android.support.v4.app
java: ... Workspace/ActionBarSherlock/src/com/actionbarsherlock/app/SherlockListFragment.java:4: cannot find symbol
symbol : class ListFragment
location: package android.support.v4.app
java: ...
Workspace/ActionBarSherlock/src/com/actionbarsherlock/widget/SuggestionsAdapter.java:33:
package android.support.v4.widget does not exist
Any help really appreciated
Edit: Seems there are no issues using Standard IntelliJ IDEA. Many guides online for setting it up with ABS. Also as Jake mentioned, he's actually been developing the thing in IntelliJ
Here is an example guide:
http://android-wtf.com/2012/09/how-to-configure-actionbarsherlock-with-intellij-idea/
However, I'm still unsure why its not working in Android Studio
Edit2: solution in answer below. In Short: (I downloaded abs latest version, extracted, deleted the old version of abs from my project, then file > import module... to import actionbarsherlock directory into my existing project. Nb, in my particular case I had an issue with junit compilation error and needed to delete \test\junit\ )

Seems there's a lot of general issues on importing modules to Android Studio, not just ActionBarSherlock, this answer might also address those. (However the last steps relating to junit are particular to abs)
The steps below allowed me to get ActionBarSherlock running with no issues.
1) Download latest ABS here: http://actionbarsherlock.com/
2) Extract ABS you should have a directory in there called "actionbarsherlock". Copy that to your Android Studio workspace. and rename to ActionBarSherlock (changed casing) -- > I now have my Android Studio Projects under \*documents*\Android Workspace\ As opposed to \Eclipse Workspace\
So you should now have something like :
\*documents*\Android Workspace\ActionBarSherlock\
Along with your main project maybe:
\*documents*\Android Workspace\TestProject\
3) Open Android Studio load your TestProject then goto File> Import Module... Now navigate to ActionBarSherlock under \*documents*\Android Workspace\ActionBarSherlock\
Click Ok and next all the way to finish. It will ask if you want to set a dependancy to the new Module (or at least mine did) click OK
4) at this point when compiling I was getting errors in \ActionBarSherlock\test\ complaining about Junit. I simply deleted the \Test\ directory from my ABS Module under project view. Right click \test\ > Delete.... You could also include the junit jar file but I don't think its necessary
5) you should now be able to compile without errors
Hopefully that helps someone.
Essentially though, I needed to re-download a completely fresh ABS, expunge my old project's ABS (which was probably quite old) then Import Module...

This works for me..
first, followed an answer provided by wired00
and I made some changes from here.
I made a build.gradle file in ActionBarSherlock library project by Generate Gradle build files from Eclipse.
edit build.gradle(for ActioBarSherlock library project) , Add a line in dependencies {}
compile files('libs/android-support-v4.jar')
edit build.gradle(for my project), delete compile files('libs/android-support-v4.jar') and add compile project(':abs') abs should be ActionBarSherlock library project name.
edit settings.gradle, add ,':abs'
delete android-support-v4.jar files except the one in the ActionBarSherlock library project

I encountered similar issue, but due to a separate problem, I can't download the latest ActionBarShelock to fix the problem as wired00 described.
If you need to stick with your existing ABS version, see if this works for you:
Click File->Project Structure.
You should see 'ActionBarSherlock' in the module list, click it.
Click the 'Dependencies' tab, very likely you do not have android support library v4 in there.
Click the '+' button at the bottom, and add android-support-v4 as a dependency. If you imported the project from Eclipse, Android Studio may have already imported the support JAR file as a library and you can use it directly. Otherwise, you may need to use the 'jars or directories' option and select the support jar file from a directory.
If your main module or other modules are also using the support library, you may need to change the setting 'Compile' to 'Provided' if you get 'DEX Already Added' errors.
You should be able to compile your ABS mobule now. If you get 'hamcrest' or 'junit' compilation errors, you may delete the 'test' folder in your ABS project as wired00 mentioned.

i also faced the same issue. i even follow the steps similar to importing ABS Library. But i was still getting the same error. Finally i solved this issue.
Solution: After following the steps similar for importing ABS Library,
Re-compile your project (Right click on your project and click on 'Compile Module "YourApp" ')
Re-compile the Library Project (Right click on Library project and click on 'Compile Module "library" ')
That's it..

Related

Adding external library in Android studio 0.3.6

So I am fairly new to Java, and I am trying to add this library to my project. The problem is that Android studio 0.3.6 doesn't have a simple way of doing that and all the answers I searched either reference an older version of Android Studio, or describe how to import an external project (source code, not jar file).
After reading a little, I got to the conclusion that manually adding the jar file would be the best way (manual copy/paste and gradle edits) but as I said, I'm fairly new to this technology and don't know where to place the file nor what lines I need to add to the gradle files.
Can someone help me?
UPDATE 1:
I finally made the IDE recognize the .jar file (I get autocomplete and class recognition). The new problem is that I get the following error when compiling: Gradle: package com.google.gson does not exist. Here are the steps I took to import the library:
Creat a folder called libs in the main directory (src/main/libs should be the result)
Copy the .jar file in that directory
add the following line to the dependencies section in the build.gradle file in your project: compile files('libs/gson-2.2.4.jar'). It should look something like this now:
dependencies {
compile 'com.android.support:support-v13:+'
compile files('libs/gson-2.2.4.jar')
}
Recompile the project (not sure if necessary, but I did it)
Right click on the libs folder and select "Add as Library"
Since the GSON library is available in MavenCentral, there's an easy way to add it that avoids having to download an archive file and save it in your project.
Go to Project Structure > Modules > Your module name > Dependencies and click on the + button to add a new dependency. Choose Maven dependency from the list:
You'll get a dialog box where you can enter search terms or the fully-qualified Maven coordinate string. Since GSON is a common library for Android developers to use, it's actually given in this dialog as an example, with the fully-qualified name. You can type it in:
Hit OK on both dialogs and you should be good to go.
With these Maven dependencies, the build system will automatically download the library and cache it if hasn't done so already; it takes care of that for you.
If you had a library that wasn't available on MavenCentral, you could save the archive in a libs folder in your project, and from that module dependencies dialog, add a File dependency instead of a Maven dependency to take care of it.
If you edit your build.gradle file by hand, you need to click on the "Sync Project with Gradle Files" button in the toolbar to force Android Studio to pick up the changes and update your project. If you go through the Project Structure dialog, that's unnecessary.
There are lots of conflicting answers to this issue in Stack Overflow because the functionality for this is in flux as the necessary features are implemented; it has been really broken before. These instructions should work properly for 0.3.6, and things will get a little easier in 0.3.7 and later.
I had the same issue. The new version of Android Studio (0.3.6) removed some necessary features to add an existing library to a project using the IDE. So you have to do this manually.
Adding the library into the build folder "<project>\App\build\libs\" will break the project on "menu > build > clear project / rebuild project".
Updated solution
My solution is to generate a new folder inside "<project>\<app name>\src\main\libs\" and add the library here. Now you have to change your "<project>\<app name>\build.gradle" by adding the following (my example shows the value for android-support library:
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile 'com.android.support:support-v13:13.0.0'
compile files('libs/gson-2.2.4.jar')
}
Now select the library in "project View" by right click and select "Add as library... > level > Global library". This will fix an import com.google.gson.Gson; issue.
Maybe you still cannot build. In this case you shall check you project module settings and see if there is an error for Gson dependency. I let Android Studio fix this issue by hitting a "small red bulb icon > add dependency" in the lower right corner of module settings dialog. Now it does not show me no errors anymore on build.
Now we have only one remaining problem: The project does lose the library reference on project close. So we have to add the library on open again. Maybe this is an issue of Android Studio 0.3.6. Mario filed a bug report.
BTW: I upvoted this question because I searched without success for a working solution in the internet. I think beginners will always fail to work with the Android developer tutorials of Google when they are forced to deal with the support library.
Update / Recommendation
Unfortunately I did not get AS 0.3.6 working properly. There are to many issues - at least when adding another module with different namespace. So I switched to the origin IDE: IntelliJ IDEA 12 community Edition. It's free and works for me. I did all the stuff in 2 hours which need days using broken Android Studio. I have no idea what forces Google to build its own IDE based on IntelliJ IDEA without additional benefits / noticeable features when the latter works like a charm.
Running Android Studio 0.4.0
Solved the problem of importing jar by
Project Structure > Modules > Dependencies > Add Files
Browse to the location of jar file and select it
For those like manual editing
Open app/build.gradle
dependencies {
compile files('src/main/libs/xxx.jar')
}
I posted the same to
importing jar libraries into android-studio
putting a duplicate here just in case you stumble into this post instead
Click on ProjectName->Libs folder.Paste that jar file into that folder.
Just refresh the project.You are done.
Using Android Studio 0.8.2, I had to do the following (supposing the library you're trying to add is called MyExternalLib):
In the "app/libs" folder on the hard disk, create a sub-folder "MyExternalLib", and copy the external library into that folder.
In the file "app/build.gradle", inside the block named "dependencies", add the line compile project('libs:MyExternalLib')
In the file "settings.gradle", add the line include ':app:libs:MyExternalLib'
Click the button "Sync Project with Gradle Files"
Create a new library module
It is good development practice to group functionality that you may reuse in other apps inside a library module. To create a library module inside the BuildSystemExample project:
Click File and select New Module.
On the window that appears, select Android Library and click Next.
Leave the default module name (lib) unchanged and click Next.
Select Blank Activity and click Next.
Type "LibActivity1" on the Activity Name field and click Finish.
The project now contains two modules, app and lib, with one activity in each module.
https://developer.android.com/sdk/installing/studio-build.html

The import android.support cannot be resolved

I am trying to run the code provided HERE
I downloaded the code from their Github and imported into Android SDK, but it shows error at the lines
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
in multiple files. However if I check the Android SDK Manager, the Android Support Library as well as the Android Support Repository in the Extras folder are both installed. I can also see the support folder and it's contents in the SDK_INSTALL\sdk\extras\android\support directory. It also has the v4 folder which also contains the android-support-v4.jar and the src folder. THen why is it still showing the error, how do I resolve it and how do I get that sample code running? THe sample code is for an RSS reader app, if that's relevant.
Follow these steps:
For Eclipse:
Go to your Project's Properties
Navigate to the Java Build Path
Then go to the Libraries tab. There click the Add External JARs Button on the Right pane.
Select the android-support-v4.jar file, usually the path for the Jar file is :
YOUR_DRIVE\android-sdks\extras\android\support\v4\android-support-v4.jar
After adding android-support-v4.jar Library, navigate to the Order and Export tab and put check mark on the android-support-v4 Library file.
After doing the above, Clean the Project and Build it.
Problem Solved.
For Android Studio:
Short Version:
Add the following line to your build.gradle file:
implementation 'com.android.support:support-v4:YOUR_TARGET_VERSION'
Long Version:
Go to File -> Project Structure
Go to "Dependencies" Tab -> Click on the Plus sign -> Go to "Library dependency"
Select the support library "support-v4 (com.android.support:support-v4:YOUR_TARGET_VERSION)"
Navigate to your "build.gradle" inside your App Directory and double check if your desired Android Support Library has been added to your dependencies.
Rebuild your project and now everything should work.
Further reading regarding this Question:
Support Library - Android Dev
Recent Support Library Revisions
Support Library Packages
What is an Android Support Library?
How do the Android Support Libraries work?
andorid-support-v4.jar is an external jar file that you have to import into your project.
This is how you do it in Android Studio:
Go to File -> Project Structure
Go to "Dependencies" Tab -> Click on the Plus sign -> Go to "Library dependency"
Select the support library "support-v4 (com.android.support:support-v4:23.0.1)"
Now to go your "build.gradle" file in your app and make sure the android support library has been added to your dependencies. Alternatively, you could've also just typed compile 'com.android.support:support-v4:23.0.1' directly into your dependencies{} instead of doing it through the GUI.
Rebuild your project and now everything should work.
Another way to solve the issue:
If you are using the support library, you need to add the appcompat lib to the project. This link shows how to add the support lib to your project.
Assuming you have added the support lib earlier but you are getting the mentioned issue, you can follow the steps below to fix that.
Right click on the project and navigate to Build Path > Configure Build Path.
On the left side of the window, select Android. You will see something like this:
You can notice that no library is referenced at the moment. Now click on the Add button shown at the bottom-right side. You will see a pop up window as shown below.
Select the appcompat lib and press OK. (Note: The lib will be shown if you have added them as mentioned earlier). Now you will see the following window:
Press OK. That's it. The lib is now added to your project (notice the red mark) and the errors relating inclusion of support lib must be gone.
For me they were appearing when i transferred code manually to another laptop. Just do
File>Invalidate Cache/Restart
click on 'Invalidate Cache and Restart' and your are done.
I followed the instructions above by Gene in Android Studio 1.5.1 but it added this to my build.gradle file:
compile 'platforms:android:android-support-v4:23.1.1'
so I changed it to:
compile 'com.android.support:support-v4:23.1.1'
And it started working.
This issue may also occur if you have multiple versions of the same support library android-support-v4.jar. If your project is using other library projects that contain different-2 versions of the support library. To resolve the issue keep the same version of support library at each place.
I have resolved it by deleting android-support-v4.jar from my Project. Because appcompat_v7 already have a copy of it.
If you have already import appcompat_v7 but still the problem doesn't solve. then try it.
This is very easy step to import any 3rd party lib or jar file into your project
Copy android-support-v4.jar file from
your_drive\android-sdks\extras\android\support\v4\android-support-v4.jar
or copy from your existing project's bin folder.
or any third party .jar file
paste copied jar file into lib folder
right click on this jar file and then click on build Path->Add to
Build Path
even still you are getting error in your project then Clean the
Project and Build it.
Android Studio 2.2.3
Linux Mint 18.1
Inside your 'project view' open Gradle Scripts -> build.gradle(Module:app) and put your mouse pointer inside the word dependencies.
Click on the light bulb and click "add library dependency" and for me all the libraries I wanted were listed there.
example libraries that came up for me:
compile 'com.android.support:gridlayout-v7:25.1.0'
compile 'com.android.support:support-v13:25.1.0'
I am now looking to add android support by default in Gradles default configuration.

Could not find xx.apk

I am a very beginer, trying to create my first Android application.
To do so, I use Eclipse and an AVD. I created my very first Class (called "Test") and when I run the project it says "Could not find Test.apk!"
I had a look at many solutions an internet:
- delete and import
- clean up my project (I have only one class so there is not much to clean
And it still does not work.
Do you have any idea about how to proceed to fix this up?
Many thank for you help.
You don't give much information to know what's wrong. What steps did you take to create this application?
Does your class Test extend the class Activity?
If it does, is it declared in your project's AndroidManifest.xml file?
Also, make sure that your project is not set up as a library project. Right click on your project's name, select Properties->Android and make sure that IsLibrary is not checked.
Possible solutions:-
Sometimes the apk file is not generated simply because there are some
android build error in your project, In this case, right click your
project, choose Android Tools -> Fix Project Properties.
Is your project termed as library, in this case, Go to
Project->Properties--> Select Android from left-hand side list -->
Uncheck the "Is Library" checkbox
Delete R.java file then clean build project or restart eclipse, this
will force the workspace to be rebuild.
what version of eclipse are you using, version of Eclipse
using(Ganymede – 3.4) is not compatible with the latest version of
the SDK. Try updating Eclipse..
Hope this helps..

In-App Billing Android and bug

Good evening, everybody.
I'm trying to debug the In-App Billing project. The sourse which I use, is
https://github.com/blundell/SimpleInAppPurchaseV3
I'm facing the problem from time to time:
Suddenly the project in file Log.java gives two errors:
1. The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
The error shows near the first symbol of the file.
R.java cannit be resolved! And gen-folder doesn't recreate! No errors in xml-files.
IabHelper.java shows the error: The import com.android.vending.billing.IMarketBillingService cannot be resolved
So if delete com.android.vending.billing/IInAppBillingService.aidl file and recreate it (by copy-paste) nothing happens.
What am I doing wrong?
I think your problem is just the latest update of the SDK.
Test the following operations on two projects :
In the project properties (eclipse) -> java build path -> order and export make sure that all your jars in the libs folder are checked.
And "Android Tools -> Fix Project Properties"
And "Project -> Clean"
If your problem persists try this:
Remove your project
Close eclipse
Import your project again
I hope you have helped!
Try this one.
1) project properties-> java build path-> order and export
make sure you have checked true all files that I have listed below:
Android Private Libraries,
Android Dependencies,
your all jar and libraries you have added.
2) check your SDK manager you have updated all required versions for
--> Tools: SDK Tools, SDK platform tools, SDK build tools.
--> Android 4.2 or what ever you are using, Google Map and SDK Platform should be updated latest.
--> Extras: Google Play Services,Google play billing libraries
also make sure you have not imported wrong variables or any class.
Hope it will help you.
Simple solution.
Rename your package name from com.android.vending.billing to com.android.vending.billing2.
Refresh project.
And after that again rename to com.android.vending.billing. And it will work.
In Android Studio click "Make Project" after adding "IInAppBillingService.aidl" file to your project. Then Android Studio can import "IInAppBillingService" class after press Alt+Enter on IInAppBillingService class.

android-support-v4.jar isn't importing correctly in Eclipse

I'm trying to get an app to compile that uses the android-support-v4.jar and the Fragmentation classes it contains, but I keep getting messages whenever I try to compile that there are errors in the code. All of the errors have to do with different Fragmentation classes that are in the .JAR. I have tried ctrl-clicking the project folder and then selecting Android Tools -> Add Compatibility Library and I keep getting this error:
[2011-12-20 11:55:31 - Android Compatibility JAR not found:]
/Applications/eclipse/Eclipse.app/Contents/MacOS/v4/android-support-v4.jar
Why would it be looking for the .JAR in Eclipse's Package Contents? I've gone into the project properties and went to the Java Build Path, and imported the .JAR from the MainActivity/libs folder, that didn't work, and then I tried to import it from my SDK directory, and that didn't work. I've fixed the project properties and cleaned and built it countless times, I've restarted Eclipse, my computer, re-downloaded and installed Eclipse, the Android SDK's and ADT and still nothing. I am completely stumped.
Edit
I've gone through the build path and imported the .JAR from both the MainActivity/libs and my SDK directory. For the hell of it I added the .JAR in the directory that keeps appearing in the errors and that hasn't worked. What's making Eclipse look for it in it's Application Package Contents?
Update
So after tinkering the project contents aren't showing any errors but the MainActivity folder still says that there is one and I still can't compile.
Like nyah:
Revision
So I think the question may be "Why is Eclipse looking for the .JAR in the Eclipse Application's package contents instead of the libs directory of the project or the Android SDK directory that I used to import it as an external .JAR?"
Update #2
I am only getting one error now after tinkering, it's on this method:
#Override
public MenuItem setOnActionExpandListener(OnActionExpandListener onActionExpandListener) {
// Noop
return this;
}
The Quick Fix says that I should delete the #Override annotation but that method must override a super class method.
These are the errors that it shows:
Multiple markers at this line
- The method setOnActionExpandListener(MenuItem.OnActionExpandListener) of type SimpleMenuItem must override a superclass method
- implements android.view.MenuItem.setOnActionExpandListener
Looks like it is looking for jar here :/Applications/eclipse/Eclipse.app/Contents/MacOS/v4/android-support-v4.jar
android-support-v4.jar is found in <sdk>/extras/android/compatibility/v4
Please make sure you add this as an external jar in the java build path
I could solve this problem by
1- delete "android-support-v4.jar" from lib
2- right click on the name of the project choose "Android Tools" and "Add Support Library"
If this is still not solved:
Like already said, in Eclipse go to your Project Properties > Java Build Path > Libs > Add External and get the one from the adk directory.
Also set up Java 1.6 as your default compile version if you already haven't. This should solve the Override Errors you described.
It turns out that my Debug Certificate had expired so I just needed to delete ~/.android/debug.keystore and restart Eclipse and everything worked.
I realize that this question has been answered, but this is a known issue that is supposed to be fixed in the ADT-17 plugin release according to comment 9 here: http://code.google.com/p/android/issues/detail?id=21488
In addition, people who have this problem can copy the compatibility JAR to the location it says it can't find it. Clearly it's looking in the wrong place (since it's checking the Eclipse directory rather than the android-sdk directory), so the simple fix, for now, is simply to put the package where it wants to find it, even though it doesn't belong.
For me it was as simple as copying the v4 directory within C:/android-sdk/extras/android/support/ into the C:/eclipse/ directory.
I had the same problem running in Ubuntu. Go to Tools->Options.
Check Force https://... to http://
Open Android SDK Manager. Check Extras->Android Support Library.
Something similar happened to me. At the top of MainActivity.java I had the next imports giving errors:
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
In each of the lines on the left they had the light bulb making some suggestions. If you click on it, one of the options will be "Fix project setup". You then will be able to choose between several options for fixing the imports, you should choose the one that specifies the android-support-v4.jar.
Right click on ur project --> select android tools --> select add support library and simply installed the supporting libraries.
Do you try not to do Android Tools -> Add Compatibility Library, and only add the jar in java build path library?.
I use this jar library of this way and it works without any problem.
I had the same problem.
Under the project properties:Java Build Path:Order and Export tab, the box next to android-support-v4.jar wasn't checked. I checked the box, and the error went away.
Another caveat was running Android SDK Manager in Windows 7 without administrator privileges. It would try to install support package, but would always fail, and the actual package never got downloaded to
C:\Program Files (x86)\Android\android-sdk\extras\android\support\v4\android-support-v4.jar
Solution: Make sure that you enter the same API for "Target SDK" and "Compile with" during Android project creation (or in the Manifest file once created).

Categories