Android Studio将基于maven的项目库添加​​为依赖项

时间:2013-10-31 07:05:22

标签: android maven gradle android-studio

我使用Android Studio开发Android应用程序,似乎使用gradle来管理依赖,

现在我想添加StickyScrollViewItems ProjectLib作为依赖项,它似乎使用maven,因为我没有看到.gradle配置文件

这是我项目的目录结构(以及我想要的)

  • [+] build
  • [o] build.gradle
  • [ - ] MyMainProject
    • [+] bin
    • [+] build
    • [o] build.gradle
    • [o] MyMainProject.MyMainProject.iml
    • [o] pom.xml
    • [ - ] src
      • [+] main
      • [+] test
  • [+] gradle
  • [o] gradlew
  • [o] local.properties
  • [o] pom.xml
  • [ - ] project-module< - 我把模块放在这里
    • [ - ] StickyScrollviewItems< - 这是模块项目的根目录
      • [ - ] library< - 似乎主要的lib就在这里
        • [o] AndroidManifest.xml
        • [ - ] gen
          • [ - ] com
            • [ - ] emilsjolander
              • [ - ] StickyScrollViewItems
                • [o] BuildConfig.java
                • [o] Manifest.java
                • [o] R.java
        • [o] library.iml
        • [o] pom.xml
        • [o] proguard-project.txt
        • [o] project.properties
        • [ - ] src
          • [ - ] com
            • [ - ] emilsjolander
              • [ - ] StickyScrollViewItems
                • [o] StickyScrollViewItems.java
      • [+] out
      • [+] sample< - ths module project working sample app
      • [o] pom.xml
      • [o] Readme.txt
  • [o] settings.gradle
  • [+] src
注:
[+]封闭目录
[ - ]打开目录
[o]文件

我怎么做,所以我可以打电话

import com.emilsjolander.SticlyScrollViewItems.R;

就像示例一样,(请参考StickyScrollViewItems中的工作示例)

顺便说一下,我的android studio版本是0.3.1,并假设我的包含主脚本的主包是com.mycompany.mymainproject


好的,我使用

成功将maven依赖项转换为gradle
gradle --setupbuild pom

这里生成的gradle文件:

StickyScrollViewItems根目录中的

settings.gradle

rootProject.name = 'parent'
include ':library', ':sample'
project(':library').projectDir = "$rootDir/library" as File
project(':sample').projectDir = "$rootDir/sample" as File
StickyScrollViewItems根目录中的

build.gradle

allprojects  {
    apply plugin: 'maven'
    group = 'com.emilsjolander.components.StickyScrollViewItems'
    version = '0.0.1-SNAPSHOT'
}

subprojects {
  apply plugin: 'java'
  sourceCompatibility = 1.6
  targetCompatibility = 1.6
  repositories {
    mavenLocal()

    maven { url "http://repo.maven.apache.org/maven2" }
  }
}
库中的

build.gradle

description = 'StickyScrollViewItems - Library'

dependencies {
    compile(group: 'com.google.android', name: 'android', version:'4.0.1.2') {
       /* This dependency was originally in the Maven provided scope, but the project was not of type war.
       This behavior is not yet supported by Gradle, so this dependency has been converted to a compile dependency.
       Please review and delete this closure when resolved. */
    }
}

现在帮助我在settings.gradle和build.gradle中编写我的prject root和MainProject文件夹

告诉我你是否需要更多信息

1 个答案:

答案 0 :(得分:0)

在MyMainProject的build.gradle文件中添加此代码

dependencies {


compile project(':StickyScrollviewItems')

}

希望这应该是有效的