[英]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:
Now you have to edit the gradle files: 现在您必须编辑gradle文件:
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之类的所有其他依赖项),如下所示: build.gradle
file of "MyApp" and add the dependencies to it build.gradle
文件并向其添加依赖项 At least you have to tell your IDE about the projectLib you use: 至少你必须告诉你的IDE你使用的projectLib:
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文件:
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:
我认为这很有用,因为声明了几个重要的事情:
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.