I\'m using Android Studio, and as you know, importing libraries used in current IDE
like Eclipse
is not easy with Android Studio. I\'m trying to im
http://www.devexchanges.info/2015/05/import-eclipse-library-non-gradle.html
This post has the best answer. But make sure your build.gradle compileSdkVersion buildTollsVersion minsdkVersion and targerSdkversion for both the app and library are the same/match.
Just so everyone knows the file structure that I am referring to (which does work):
In your APP's build.gradle
file make sure you have:
dependencies {
// Your other dependencies go here
compile project(':libraries:SlidingMenu')
}
In your SLIDING MENU's build.gradle
file make sure it has the following:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
java.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
}
Your PROJECT'S settings.gradle
file should look like this:
include ":libraries:SlidingMenu", ':App'
In android studio press the Tools -> Android -> Sync Project with Gradle Files
button, then rebuild your project. If all went well you should be able to import the com.jeremyfeinstein.slidingmenu.lib.SlidingMenu
library into your app's source files.
I assume you already have a runnable project in android and you want to add the SlidingMenu
lib to it.
First you should export the lib in Eclipse like it is described on the android developer site.
Than in AS:
Now you have to edit the gradle files:
settings.gradle
file of you root project: there you have to add all your modules (-> your MainProject and all other dependencies like your lib) like this:build.gradle
file of "MyApp" and add the dependencies to itAt least you have to tell your IDE about the projectLib you use:
In this post you can see how to add ABS to your project.
Update 2013-10-01
Generate build.gradle files with eclipse:
After these steps you should see a build.gradle
file in your project lib.
In Android Studio:
Create a folder named "lib" in your project and copy the whole project lib (with the build.gradle file) into this folder.
After these steps your folder structure should look like this:
MyAppProject
- lib
-- SlidingMenu
--- build.gradle
- MyApp
-- src
-- build.gradle
-- MyApp.iml
- build.gradle
- settings.gradle
After this you have to edit build.gradle
in "MyApp" (-> adding the dependencies) and settings.gradle
in "MyAppProject" (--> including the modules: "MyApp" and "SlidingMenu"). Please look at the post below how to do that.
In this post I tried to import ABS to my project. I think this is helpful, because there are several important things declared:
Update 2013-10-02
buildscript {
// define the repo which is to use
repositories {
mavenCentral()
}
// define the classpath for Gradle Android Plugin
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
// declaring that the project is a library
apply plugin: 'android-library'
// declaring all dependencies the project needs
dependencies {
// SlidingMenu is using the support lib v4
// -> this jar file is included in the folder "libs"
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
// this values you can read out from the Manifest (but I add the right values for you)
minSdkVersion 5
targetSdkVersion 17
}
// because Android Studio has a different file structure than Eclipse
// you have to say Android Studio where the files are located
sourceSets{
main{
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
// resources.srcDirs = ['src']
// aidl.srcDirs = ['res']
// assets.srcDirs = ['assets']
// renderscript.srcDirs = ['src']
}
}
}
this library is deprecated. just using from below library
implementation 'com.github.androidlibraries:slidingmenu:1.0.0'
note: dont forget using this
maven { url "https://jitpack.io" }
in repositories block
Better yet: Use this https://github.com/jzaccone/SlidingMenu-aar
Just add the following to your build.gradle
repositories {
maven { url "http://jzaccone.github.io/SlidingMenu-aar" }
...
}
dependencies {
compile 'com.jeremyfeinstein.slidingmenu:library:1.3@aar'
...
}
It's slightly out of date - but it's better than AndroidStudio not recognizing the class files (which happened to me), and the fix described here didn't work either: https://stackoverflow.com/a/21170839/1639040