How to import slidingmenu on Android Studio?
Asked Answered
A

4

22

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.

Ardyth answered 29/9, 2013 at 14:16 Comment(0)
A
30

Just so everyone knows the file structure that I am referring to (which does work):

File structure I will be referencing

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.

Avron answered 20/12, 2013 at 22:49 Comment(1)
Your instructions are quite good, still it took me hours because the SlidingMenu module did not show up in AndroidStudio. The only thing which helped was to create a new dummy-module. Afterwards I removed it again.Adessive
L
33

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

Lenoralenore answered 24/3, 2014 at 21:0 Comment(2)
I can't believe the library has over 5k stars but still isn't officially available in Maven.Triple
I get Error:(40, 13) Failed to resolve: com.jeremyfeinstein.slidingmenu:library:1.3Ding
A
30

Just so everyone knows the file structure that I am referring to (which does work):

File structure I will be referencing

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.

Avron answered 20/12, 2013 at 22:49 Comment(1)
Your instructions are quite good, still it took me hours because the SlidingMenu module did not show up in AndroidStudio. The only thing which helped was to create a new dummy-module. Afterwards I removed it again.Adessive
T
5

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:

  1. Import the SlidingMenu Project in eclipse (I assume you know how to do that)
  2. In Eclipse: Right click on the project lib -> Export
  3. 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']
        }
    }
}
Tautology answered 30/9, 2013 at 6:29 Comment(12)
I don't understand your first step. I'm sorry I'm a beginer, but can you show me step by step how you do? It may be helpfull for me, and for others I think.Ardyth
It's a little bit difficult to give you a "step-by-step" instruction, because I really don't know what you can do and what not (my answer above already is a instruction but not in detail :)). I updated my answer with a link to a question where I had the same problem to import/include project libs. You don't need to export the project lib from eclipse, you can create the build.gradle file on your own...but it would be simpler with eclipse (in my answer above I try to explain the export)...Try to explain what your problems are, what you did and where you get errors or where you failed.Tautology
Thanks a lot for your time and explanations. I will try this when I enter my home tonight (I leave in France so it's just 9:00 now).Ardyth
So, I'm doing what you said me, but I have problems when i build in Eclipse. I'm sorry again, I've juste installed it and I don't know well how it works. So I request you : could you help me in private ? (using TeamViewer for example, and Skype).Ardyth
I think its better to create a 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
Ok, I will try with your build.gradle. Thanks for your help and your time :)Ardyth
So, I've tried to import the library as you said (I've made a copy of library folder in my project) and added a dependency to that library but it still doesn't works. What is the problem with this library and AS ?Ardyth
Could you upload your project that I can download it? To see whats the problem.Tautology
Ok, so I've uploaded it. First time I use this host so sorry if it's bad. uploadhero.co/dl/4FFNrOf5Ardyth
I didn't import your project to my AS, because I just installed it at my home pc. But I saw in your gradle files some mistakes: first you have to include the library in the "settings.gradle" (-> Update 2013-10-01: "code for settings.gradle") file and second you need a "build.gradle" file in your library (-> Update 2013-10-02).Tautology
And you have to add the library in you dependency as a project (-> "compile project(:path)"). Also your library project isn't complete...the manifest is missing.Tautology
I don't understand what you mean, I did not touch the manifest file... Could you upload a Project as you do ? It will help me a lot to understand my mistakes.Ardyth
H
0

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

Hawkeyed answered 7/12, 2018 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.