How do I add a library (android-support-v7-appcompat) in IntelliJ IDEA

How do I add a library (android-support-v7-appcompat) in IntelliJ IDEA



I created a project, copied the resource files in the project, library, added it to the project structure, prescribed style Theme.AppCompat.
Compiled without errors, but when you start the relegation Exception:


Theme.AppCompat


08-03 00:50:00.406: ERROR/AndroidRuntime(4055): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:98)
at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
at com.example.SampleMetrRost.CentralActivity.onCreate(CentralActivity.java:12)
at android.app.Activity.performCreate(Activity.java:4636)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1051)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1924)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4476)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:583)
at dalvik.system.NativeStart.main(Native Method)



Help me, please. Spent all day today.





Ran into the same problem, check stackoverflow.com/a/18916738/183575 for a simple and clean way to solve it.
– RedGlyph
Sep 20 '13 at 12:26





youtube.com/watch?v=MIzgaMiyKoM
– Behzad
Aug 4 '14 at 23:21




9 Answers
9



Create a support library project.



Import your library project to Intellij from Eclipse project (this step only applies if you created your library in Eclipse).



Right click on module and choose Open Module Settings.



Setup libraries of v7 jar file
Setup libraries of v7 jar file



Setup library module of v7
Setup library module of v7



Setup app module dependency of v7 library module
Setup app module dependency of v7 library module





Very, very Thanks, very helpful.
– Alex Malkov
Aug 12 '13 at 12:32





This saved me a couple hours at least. Thanks a lot!
– Maciej Swic
Oct 23 '13 at 14:51





Could you elaborate a bit on how you get to step 5? I'd be very grateful... Thanks!
– Andreas Wong
Jun 17 '14 at 9:25





@SiGanteng Step 5 is actually done automatically when you perform step 1 & 2
– Populus
Aug 21 '14 at 15:52




If you are using Gradle, you can add it as a compile dependency.


compile



Instructions



Make sure you have the Android Support Repository SDK package installed. Android Studio automatically recognizes this repository during the build process (not sure about plain IntelliJ).


Android Support Repository



Android Support Repository



Add the dependency to project/build.gradle


project/build.gradle


dependencies
compile 'com.android.support:appcompat-v7:+'



Click the Sync Project with Gradle Files button.


Sync Project with Gradle Files



EDIT: Looks like these same instructions are on the documentation under Adding libraries with resources -> Using Android Studio.


Adding libraries with resources -> Using Android Studio





Thanks, but I do not use Gradle. I do not have Android Studio I program in the IntelliJ IDEA
– Alex Malkov
Aug 2 '13 at 21:56





I mostly added this in case someone else found your question and used Gradle. This should work if someone has the Android plugins for IntelliJ and uses Gradle.
– Austyn Mahoney
Aug 2 '13 at 22:11





Thanks for adding. Have you ever added the support library to a android library project and tried to run a app depending on the android library project? I seem to always get a "already added" exception while compiling. Not sure why - it is only added on the library project.
– Eggman87
Sep 21 '13 at 2:08





For the record: it works the same way with plain IntelliJ. You'll just need to "Make project" once you finish installing the "Android Support Repository".
– jpkrohling
Feb 6 '14 at 11:31





@Eggman87 I know this is late, but try com.android.support:support-v4:+ in your library project. This will tell it to use whatever version the project using it provides.
– Austyn Mahoney
Mar 31 '14 at 17:00


com.android.support:support-v4:+



Using Maven



First of all you should install android libraries to your local maven repository using Maven Android SDK Deployer



Then you can add dependency to your pom like this:


<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v7-appcompat</artifactId>
<version>$compatibility.version</version>
<type>apklib</type>
</dependency>

<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v7-appcompat</artifactId>
<version>$compatibility.version</version>
<type>jar</type>
</dependency>





The Deployer didn't work for me. Instead I followed these steps: 1) Goto ANDROID_HOMEsdkextrasandroidsupportv7appcompat 2) Create a zip file of the entire library and call it appcompat.apklib 3) Open cmd in this location and type "mvn install:install-file -Dfile=appcompat.apklib -DgroupId=com.google.android -DartifactId=support-v7-appcompat -Dversion=r7 -Dpackaging=apklib" 4) Goto /libs 5) Type "mvn install:install-file -Dfile=android-support-v7-appcompat.jar -DgroupId=com.google.android -DartifactId=support-v7-appcompat -Dversion=r7 -Dpackaging=jar" 6) Add the appropriate dependencies
– bentzy
Feb 13 '14 at 9:56





This was usefull as well: code.google.com/p/maven-android-plugin/wiki/ApkLib
– bentzy
Feb 13 '14 at 9:57




This is my solution:



Copy&paste $ANDROID_SDK/extras/android/support/v7/appcompat to your project ROOT



Open "Project Structure" on Intellij, click "Modules" on "Project Settings", then click "appcompat"->"android', make sure "Library Module" checkbox is checked.



click "YOUR-PROJECT_NAME" under "appcompat", remove "android-support-v4" and "android-support-v7-compat"; ensure the checkbox before "appcompat" is checked. And, click "ok" to close "Project Structure" dialogue.



back to the mainwindow, click "appcompat"->"libs" on the top-left project area. Right-click on "android-support-v4", select menuitem "Add as library", change "Add to Module" to "Your-project". Same with "android-support-v7-compat".



After doing above, intellij should be able to correctly find the android-support-XXXX modules.



Good Luck!



Another yet simple solution is to paste these line into the build.gradle file


dependencies

//import of gridlayout
compile 'com.android.support:gridlayout-v7:19.0.0'
compile 'com.android.support:appcompat-v7:+'





It's not a good idea to ask for the latest version of appcompat. Instead, use this: compile 'com.android.support:appcompat-v7:targetSdkVersion.+'
– Vikram Bodicherla
Sep 6 '15 at 20:27



Another solution for maven (and a better solution, for me at least) is to use the maven repository included in the local android SDK. To do this, just add a new repository into your pom pointing at the local android SDK:


<repository>
<id>android-support</id>
<url>file://$env.ANDROID_HOME/extras/android/m2repository</url>
</repository>



After adding this repository you can add the standard Google dependency like this:


<dependency>
<groupId>com.android.support</groupId>
<artifactId>support-v13</artifactId>
<version>$support-v13.version</version>
</dependency>

<dependency>
<groupId>com.android.support</groupId>
<artifactId>appcompat-v7</artifactId>
<version>$appcompat-v7.version</version>
<type>aar</type>
</dependency>



You should add the resources in a library project as per http://developer.android.com/tools/support-library/setup.html



Section > Adding libraries with resources



You then add the android-support-v7-appcompat library in your workspace and then add it as a reference to your app project.


android-support-v7-appcompat



Defining all the resources in your app project will also work (but there are a lot of definitions to add and you have missed some of them), and it is not the recommended approach.





Please also note, that if you defining all resources from appcompat project to your project, you should check that R.java generated file should be in android.support.v7.appcompat package. Otherwise, resources won't be visible by android-support-v7-appcompat.jar
– Antonio
Aug 2 '13 at 21:45


android.support.v7.appcompat





I am using IDEA, tell me, please, how to add a library with resources. Resources he sees compile without errors, but when you start getting out the error
– Alex Malkov
Aug 3 '13 at 7:20




This is my solution, it is very similar to the previous one:


<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v7</artifactId>
<scope>system</scope>
<systemPath>$android.home/support/v7/appcompat/libs/android-support-v7-appcompat.jar</systemPath>
<version>19.0.1</version>
</dependency>



Where android.home is the root directory of the Android SDK and it uses systemPath instead of repository.





support-v7 is not just a simple jar file
– Serob_b
Feb 3 '17 at 5:17



As an update to Austyn Mahoney's answer, configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.



It will be removed at the end of 2018. For more information see here.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)