简体   繁体   English

如何在Android Studio上导入slidemenu?

[英]How to import slidingmenu on Android Studio?

I'm using Android Studio, and as you know, importing libraries used in current IDE like Eclipse is not easy with Android Studio. 我正在使用Android Studio,如您所知,使用Android Studio导入当前IDE使用的库(如Eclipse )并不容易。 I'm trying to import the slidingmenu lib into my project but I don't know how to do it well. 我正在尝试将slidingmenu库导入我的项目,但我不知道如何做得好。 I've tried as they said in this link How to import slidingmenu on Intellij Idea? 我试过他们在这个链接中说如何在Intellij Idea上导入滑动菜单? But I failed again. 但我又失败了。 So I hope someone can answer me and show me how it works. 所以我希望有人能回答我,告诉我它是如何运作的。

Better yet: Use this https://github.com/jzaccone/SlidingMenu-aar 更好的是:使用此https://github.com/jzaccone/SlidingMenu-aar

Just add the following to your build.gradle 只需将以下内容添加到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 它有点过时 - 但它比AndroidStudio更好地不识别类文件(发生在我身上),并且这里描述的修复也不起作用: https//stackoverflow.com/a/21170839/1639040

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: APP的 build.gradle文件中,请确保您具有:

dependencies {
    // Your other dependencies go here
    compile project(':libraries:SlidingMenu')
}

In your SLIDING MENU's build.gradle file make sure it has the following: SLIDING MENU的 build.gradle文件中,确保它具有以下内容:

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: 您的PROJECT'S settings.gradle文件应如下所示:

include ":libraries:SlidingMenu", ':App'

In android studio press the Tools -> Android -> Sync Project with Gradle Files button, then rebuild your project. 在android studio中按Tools -> Android -> Sync Project with Gradle Files按钮,然后重建您的项目。 If all went well you should be able to import the com.jeremyfeinstein.slidingmenu.lib.SlidingMenu library into your app's source files. 如果一切顺利,您应该能够将com.jeremyfeinstein.slidingmenu.lib.SlidingMenu库导入到您应用的源文件中。

I assume you already have a runnable project in android and you want to add the SlidingMenu lib to it. 我假设你已经在android中有一个可运行的项目,你想要添加SlidingMenu lib。

First you should export the lib in Eclipse like it is described on the android developer site . 首先,你应该像在android开发者网站上描述的那样在Eclipse中导出lib。

Than in AS: 比AS:

  • create in the root project folder a folder named "lib" 在根项目文件夹中创建名为“lib”的文件夹
  • copy the exported project lib to this folder 将导出的项目lib复制到此文件夹

Now you have to edit the gradle files: 现在您必须编辑gradle文件:

  • 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: 首先编辑你的根项目的settings.gradle文件:你需要添加所有模块( - >你的MainProject和你的lib之类的所有其他依赖项),如下所示:
  • Than you have to edit the build.gradle file of "MyApp" and add the dependencies to it 您必须编辑“MyApp”的build.gradle文件并向其添加依赖项

At least you have to tell your IDE about the projectLib you use: 至少你必须告诉你的IDE你使用的projectLib:

  • right click on your main module "MyApp" -> Open Modeule Settings 右键单击主模块“MyApp” - >打开Modeule设置
  • click on the plus and "import module" 点击加号和“导入模块”
  • choose the "build.file" of you slidingMenuLib 选择slidingMenuLib的“build.file”

In this post you can see how to add ABS to your project . 在这篇文章中,您可以看到如何将ABS添加到您的项目中

Update 2013-10-01 更新2013-10-01

Generate build.gradle files with eclipse: 使用eclipse生成build.gradle文件:

  1. Import the SlidingMenu Project in eclipse (I assume you know how to do that) 在eclipse中导入SlidingMenu项目(我假设你知道怎么做)
  2. In Eclipse: Right click on the project lib -> Export 在Eclipse中:右键单击项目lib - > Export
  3. Choose: Android -> Generate Gradle build files 选择:Android - >生成Gradle构建文件

After these steps you should see a build.gradle file in your project lib. 完成这些步骤后,您应该在项目库中看到build.gradle文件。

In Android Studio: 在Android Studio中:

Create a folder named "lib" in your project and copy the whole project lib (with the build.gradle file) into this folder. 在项目中创建名为“lib”的文件夹,并将整个项目库(使用build.gradle文件)复制到此文件夹中。

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"). 在这之后,你必须编辑build.gradle在“MyApp的”( - >添加依赖)和settings.gradle在“MyAppProject”( - >包括模块:“MyApp的”和“SlidingMenu”)。 Please look at the post below how to do that. 请看下面的帖子如何做到这一点。

In this post I tried to import ABS to my project. 这篇文章中,我尝试将ABS导入到我的项目中。 I think this is helpful, because there are several important things declared: 我认为这很有用,因为声明了几个重要的事情:

  • project structure 项目结构
  • code for build.gradle build.gradle的代码
  • code for settings.gradle settings.gradle的代码

Update 2013-10-02 更新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']
        }
    }
}

http://www.devexchanges.info/2015/05/import-eclipse-library-non-gradle.html 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. 但是请确保app和库的build.gradle compileSdkVersion buildTollsVersion minsdkVersion和targerSdkversion是相同/匹配的。

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 存储库块中的maven { url "https://jitpack.io" }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM