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 import the slidingmenu
lib into my project but I don't know how to do it well. I've tried as they said in this link How to import slidingmenu on Intellij Idea?
But I failed again. So I hope someone can answer me and show me how it works.
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.
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://mcmap.net/q/587005/-how-do-i-import-com-google-android-gms-in-android-studio-using-a-gradle-build
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:
- create in the root project folder a folder named "lib"
- copy the exported project lib to this folder
Now you have to edit the gradle files:
- first edit the
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: - Than you have to edit the
build.gradle
file of "MyApp" and add the dependencies to it
At least you have to tell your IDE about the projectLib you use:
- right click on your main module "MyApp" -> Open Modeule Settings
- click on the plus and "import module"
- choose the "build.file" of you slidingMenuLib
In this post you can see how to add ABS to your project.
Update 2013-10-01
Generate build.gradle files with eclipse:
- Import the SlidingMenu Project in eclipse (I assume you know how to do that)
- In Eclipse: Right click on the project lib -> Export
- Choose: Android -> Generate Gradle build files
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:
- project structure
- code for build.gradle
- code for settings.gradle
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']
}
}
}
build.gradle
file for the SlidingMenu on your own, before wasting time to configure Eclipse. Try to build it in Android Studio. I add to my answer above the build.gradle
file you have to use for the library. At the weekend I could look at your files or I could generate a 'HelloWorld' project with the SlidingMenu and upload it to git. But try it first on your own :) –
Tautology 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
© 2022 - 2024 — McMap. All rights reserved.