I am developing an Android app and I'm trying to include GraphView to plot some graphs.
It is required to include it as a module dependency. After I do that, the IntelliJ IDE properly detects the packages and I can import them, but compiler throws errors when trying to compile:
package com.jjoe64.graphview.GraphView does not exist
cannot find symbol class GraphView
etc.
I followed this guide to include it: http://wiki.jetbrains.net/intellij/Sharing_and_re-using_Android_resources_through_library_projects
If it still occures to anyone , for me the reason was that the module's Android class libarary source folder was not marked as 'Sources' directory .
Simply click on the sources folder and choose mark directory as --> source folder.
After that instead of compile , choose 'make' , and then it will start working for you.
Best of luck with that annoying bug !
I had the same problem and this is how I solved it:
I was using Gradle so I right-clicked on the build.gradle.kts (it may just be build.gradle in your case) and clicked on "Import Gradle project" and everything worked again!
Related
I'm using IntelliJ/Android Studio with Ant build (not Gradle at the moment), and am trying to use android-support-v7-cardview.jar but I continue to get
android.view.InflateException: Binary XML file line #19: Error inflating class android.support.v7.widget.CardView
java.lang.NoClassDefFoundError: android.support.v7.cardview.R$styleable
I am not using m2repository with the aar file, but am using the cardview at location
sdk/extras/android/support/v7
I have gotten it to work by using the classes from the jar in my own project, but it requires API 21 (5.0) which I don't want to use yet. I am trying to use the jar file in the libs folder and res files from
sdk/extras/android/support/v7/cardview/res
I have added the lib file and res files to my own project, but still get the error messages above. What should I do?
I had the exact same problem after adding compile 'com.android.support:cardview-v7:23.2.1' to build.gradle's dependencies to use the CardView, however after cleaning the project (Build > Clean Project) everything worked like magic.
Hi this might be helpful, this worked for me. (for intellij users)
click in your project,
right click -> open Module Settings (f4)
import cardview from \sdk\extras\android\support\v7\
add .jar file to cardview module
click on your project and give module dependency to cardview
now, click (+) button on cardview -> android -> at top you will see a check box (library module), enable it.
click ok and close your settings dialog.
rebuild your project and run it.
I think you have to import it as an Android library project, then the ressources should be found correctly. I also tried first to import only the jar which didn't work, so I did it this way:
The project for the CardView is located in your Android SDK folder: Android\android-sdk\extras\android\support\v7\cardview
In Eclipse use "Import" and select "Existing Android Code Into Workspace" and import the CardView project
Go to Properties->Android of the new project, mark it as a library project and then Link it as a library project in your own project where the CardView can not be found
That should do it
I didn't figure out the error really but I just commented out the stuff that uses Android 5.0 in the source code of the library and it works fine. I didn't want to use a minSdk of Android 5.0.
If you are using Android Studio then its quick easier, Please add compile 'com.android.support:cardview-v7:21.+' in dependencies in build.gradle.
dependencies {
compile 'com.android.support:cardview-v7:21.+'
}
I know that there are different solutions with different libraries posted. But, could anyone help me with this one?
I've busting my head for the past couple of days, and I really don't know what to do. I already tried importing the modules in all the suggested ways from different posts. (Project Structure --> Dependencies --> Add dependencies), etc. My project does not show any errors, but when I run it, it throws me a compilation error that complains about some classes missing. The library only depends on the ViewPagerIndicator's library which I also imported.
here is a picture. Thanks!!!
NOTE:I also have tried it with Eclipse, but the problem is different there. The app crashes when I run it. When I uncheck isLibrary from Properties -> Android and erase those libraries, the app works.
Inspired by this answer, these are the steps I did:
Put the jar file (in my case, 'xxx.jar') into the libs folder of your project
Right click it and select Add as library
Type this in the dependencies part of build.gradle file: compile files('libs/xxx.jar')
Do a clean build. It can be done inside the android studio, but I also ran the gradlew.bat included inside the project folder
Now, the project should be built and run just fine.
You are referencing the library wrong. You need to add the dependency in the build.gradle file. I recommend you to read the documentation first. It's a long read, but totally worth it.
I noticed that a user uploaded the library as .aar file in his maven repo. You might want to use the library from his repo. The setup is very easy (you only need to include the dependency of the better picker library).
I recently downloaded Android Studio to develop Android applications (I'm coming from Eclipse), and I am having issues using external libraries and/or external JAR files alongside my own project. NOTE: the following tests were conducted on a new application project created from scratch in Android Studio.
Example 1: JAR Import.
Download a fresh copy of the Admobs SDK from Google.
Copy the library jar GoogleAdMobAdsSdk-6.4.1.jar to the project's /libs/ folder.
In the project explorer, right click on the newly added library.jar and click on 'Add as Library'.
Technically at this point everything works, imports work just fine, the layout editor shows a preview of the AdView widget and all that. The only problem is that it doesn't compile successfully.
Log from console:
Gradle:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':APITests:compilePaidDebug'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
I tried running gradlew compileDebug --stacktrace, and the problem seems to be that the despite being able to import the classes successfully in both the code & design editor, at compile time, it cannot resolve the imports. Here's the relevant part of the log: (full stacktrace here)
java:6: error: package com.google.ads does not exist
import com.google.ads.AdRequest;
java:7: error: package com.google.ads does not exist
import com.google.ads.AdView;
java:11: error: cannot find symbol
AdView mAdView;
symbol: class AdView
location: class MainActivity
java:22: error: cannot find symbol
mAdView = (AdView)this.findViewById(R.id.adView);
symbol: class AdView
location: class MainActivity
java:23: error: cannot find symbol
mAdView.loadAd(new AdRequest());
symbol: class AdRequest
location: class MainActivity
5 errors
:Test:compileDebug FAILED
But again, the imports work well in the editor, and the dependency is there:
It's also worth noting that without attempting to add a library/JAR, the projects compiles just fine.
I then tried editing the build.gradle file to include the new lib like this:
dependencies {
compile files('libs/android-support-v4.jar', 'libs/GoogleAdMobAdsSdk-6.4.1.jar')
}
This time, it did compile successfully, but the app now forces closes, as apparently, it cannot find a specific class from the lib in the application package.
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: /data/app/com.foo.test-1.apk
Any ideas?
So,
Steps to follow in order to import a JAR sucesfully to your project using Android Studio 0.1.1:
Download the library.jar file and copy it to your /libs/ folder inside your application project.
Open the build.gradle file and edit your dependencies to include the new .jar file:
compile files('libs/android-support-v4.jar', 'libs/GoogleAdMobAdsSdk-6.4.1.jar')
File -> Close Project
Open a command prompt on your project's root location, i.e 'C:\Users\Username\AndroidStudioProjects\MyApplicationProject\'
On the command prompt, type gradlew clean, wait till it's done.
Reopen your application project in Android Studio.
Test run your application and it should work succesfully.
You don't need to close the project and go to command line to invoke grade:clean.
Go to Build-> Rebuild Project
Easy way and it works for me. Using Android Studio 0.8.2.
Drag jar file under libs.
Press "Sync Project with Gradle Files" button.
"simple solution is here"
1 .Create a folder named libs under the app directory for that matter any directory within the project..
2 .Copy Paste your Library to libs folder
3.You simply copy the JAR to your libs/ directory and then from inside Android Studio, right click the Jar that shows up under libs/ > Add As Library..
Peace!
Here is how I got it going specifically for the admob sdk jar file:
Drag your jar file into the libs folder.
Right click on the jar file and select Add Library
now the jar file is a library lets add it to the compile path
Open the build.gradle file (note there are two build.gradle files at least, don't use the root one use the one in your project scope).
Find the dependencies section (for me i was trying to the admob -GoogleAdMobAdsSdk jar file)
e.g.
dependencies {
compile files('libs/android-support-v4.jar','libs/GoogleAdMobAdsSdk-6.3.1.jar')
}
Last go into settings.gradle and ensure it looks something like this:
include ':yourproject', ':yourproject:libs:GoogleAdMobAdsSdk-6.3.1'
Finally, Go to Build -> Rebuild Project
you export the project from Eclipse and then import the project from Android Studio, this should solve your problem, open a eclipse project without importing it from Android Studio you can cause problems, look at:
(Excuse my language, I speak Spanish.)
http://developer.android.com/intl/es/sdk/installing/migrate.html
I had the problem not able to load jar file in libs folder in Android Studio.
If you have added JAR file in libs folder, then just open build.gradle file and save it without editing anything else. If you have added this line
compile fileTree(dir: 'libs', include: ['*.jar'])
save it and clean the project .. In next build time Android Studio will load the JAR file.
Hope this helps.
I'm using Android Studio 0.5.2. So if your version is lower than mine my answer may not work for you.
3 ways to add a new Jar to your project:
Menu under Files-->Project Structure
Just press 'F4'
under Project navigation, right clink on any java library and a context menu will show then click on 'Open Library Settings'
A Project Structure window will popup.
On the left column click on 'Libraries' then look at the right pane where there is a plus sign '+' and click on it then enter the path to your new library.
Make sure the new library is under the 'project\libs\' folder otherwise you may get a broken link when you save your project source code.
I am currently using Android Studio 1.4.
For importing and adding libraries, I used the following flow ->
1. Press **Alt+Ctr+Shift+S** or Go to **File --> Project** Structure to open up the Project Structure Dialog Box.
2. Click on **Modules** to which you want to link the JAR to and Go to the Dependency Tab.
3. Click on "**+**" Button to pop up Choose Library Dependency.
4. Search/Select the dependency and rebuild the project.
I used the above approach to import support v4 and v13 libraries.
I hope this is helpful and clears up the flow.
I use android studio 0.8.6 and for importing external library in project , paste that library in libs folder and inside build.gradle write path of that library inside dependencies like this
compile files('libs/google-play-services.jar')
In Android Studio (mine is 2.3.1) go to File - Project Structure:
Check the libs version requirements. The lib might be trying to call a method from from a higher Android version. Try adding the apps compatability libs.
When all else fails try switching from a Gradle build to an Eclipse build.
Delete and restructure your folders to the eclipse style and delete everything but your code. Then reload the project with your libs.
Once it runs go back to Gradle, if you wish.
I followed demo instructions on page http://www.achartengine.org/content/goodies.html
i successfully imported the demo project, but every chart give throws
a NoClassDefFoundError at runtime, similar to this:
java.lang.NoClassDefFoundError:
org.achartengine.model.XYMultipleSeriesDataset
achartengine-1.0.0.jar is on build path, and it is reported under
'Referenced Libraries'. I guess this is a newbie problem, but I
decided to report it since I just imported the demo project 'as is'
and tried to run it on my phone.
Do I need other steps, not listed on 'goodies' page?
I found a good answer on google groups, tested it and it seems to be working:
The only thing that I have ever came across in this case is the export of the jar ... if that makes sense.
In Eclipse:
Right click your project - go to build path - select Configure build
path
go to the "Order and Export" tab
Check the "achartengine-1.0.0.jar box and then single click its name
move it up so its right below the Android dependancies (sometimes this can make a difference if you have multiple Jars)
click ok then clean your project. (Project -> Clean...)
Remind to change the "lib" directory to "libs" first !
Then CHECK the box of achartengine-1.0.0.jar and move it over the Android Dependencies in the "Configure build path" - "Order and Export" tab"!
The error (NoClassDefFoundError) you are seeing is runtime error. Referenced library solves only compile time error not runtime error. Add those jars to lib folder of your project. Those jars should be available at runtime also.
The answer from 'Shine' worked with the addition of removing import of android.R from PieChartBuilder and removing two #Overrides from PieChartBuilder and XY_ChartBuilderbefore Eclipse would agree to compile.
You need simply to add your jar files to the Libraries folder. It should work fine.
I am attempting to follow along to this tut: HERE but using a sprite sheet and animating the sprites. The app builds clean, no errors or warnings, but at runtime i get a java.lang.NoClassDefNotFound error on CCGLSurfaceView, even though i have the library in the class path and have even attached the source code. here is a pic of the error and the library in the package explorer in the apps project folder.
the error throws on line 26 in the screen. anyone know what might be the culprit? i realize that it is saying the class file isn't in the classpath but when i right click on the library in the package explorer and go Build Path > , i have the option to remove from the build path, so i know it is in there. for some reason I'm pretty stumped right now, so any help would be appreciated. thanks.
Ok since you updated to revision 17 you should put your libraries in a folder libs in the root of your project. The Android build system will do the rest there is no need to manually add the library to the build path.
The change is descibed at the tools.android.com homepage: Dealing with dependencies in Android projects
Well it's been 1 year, but the answer is to remove the cocos2d android.jar from the Java build path..
In Eclipse, right click your folder-->Properties-->Java Build Path-->Libraries remove cocos2d.jar and after that drag the cocos2d.jar into your libs folder in Eclipse.
Lastly, right click folder-->Android Tools-->Fix Project Properties and run it. It should be ok. Note: After fixing project properties jar files will have a little library images.