How to import slidingmenu on Android Studio?

落花浮王杯 提交于 2019-12-17 15:31:39

问题


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.


回答1:


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.




回答2:


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




回答3:


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']
        }
    }
}



回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/19079072/how-to-import-slidingmenu-on-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!