相关疑难解决方法(0)

如何用Android Studio和gradle构建一个Android库?

我正在尝试从Eclipse迁移项目,但我尝试过的任何工作都没有.在Eclipse中我有3个项目(2个Android应用程序项目和1个android库项目).2个app项目取决于库项目.当我进行gradle导出时,我得到3个不起作用的项目.我愿意重组该项目,但没有找到任何关于如何完成这项工作的文件.

有没有办法让Eclipse导出的3个项目一起工作?我是否最好重组一些事情,如果是这样的文件应该怎么做呢?

更新

我已将整个项目上传到GitHub https://github.com/respectTheCode/android-studio-library-example

更新1

根据Padma Kumar的建议,这就是我所尝试的.

  1. 创建一个名为的新项目 MyApp
  2. 单击File > New Module,选择Android Library并命名MyLib
  3. 点击 Build > Make Project

构建因此错误而失败

Module "MyLib" was fully rebuilt due to project configuration/dependencies changes
Compilation completed with 1 error and 0 warnings in 19 sec
1 error
0 warnings
/.../MyApp/MyLib/build/bundles/debug/AndroidManifest.xml
Gradle: <manifest> does not have package attribute.
Run Code Online (Sandbox Code Playgroud)

然后我package在清单中添加了一个属性

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.mylib" >
Run Code Online (Sandbox Code Playgroud)

建成后我得到了这个错误

Module "MyApp" was fully rebuilt due to project configuration/dependencies changes
Compilation completed with …
Run Code Online (Sandbox Code Playgroud)

android gradle android-studio

143
推荐指数
2
解决办法
17万
查看次数

在Android studio中添加外部库

我想在我的Android应用程序中添加外部库https://github.com/foursquare/foursquare-android-oauth(我使用Android Studio,lib作者为Eclipse提供的说明不适用于Android Studio).

我已经尝试用maven做了,所以在File-> Project Structure-> Dependencies中我添加com.foursquare:foursquare-android-nativeoauth-lib:1.0.0但是Gradle Sync失败了:

Error:Failed to find: com.foursquare:foursquare-android-nativeoauth-lib:1.0.0
Run Code Online (Sandbox Code Playgroud)

当我尝试构建我的应用程序(没有修复上面的错误,因为我不知道如何)我得到:

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not resolve com.foursquare:foursquare-android-nativeoauth-lib:1.0.0.
 Required by:
    ForSquaresOnly:app:unspecified
   > Could not parse POM http://jcenter.bintray.com/com/foursquare/foursquare-android-nativeoauth-lib/1.0.0/foursquare-android-nativeoauth-lib-1.0.0.pom
     > Could not find any version that matches com.foursquare:parent:1.0.0.
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以导入这个lib?我可以简单地将源代码复制粘贴到我的源代码中或从中创建JAR吗?

顺便说一句:如果遇到问题,请看这个问题(导入后我遇到了这个问题):清单合并失败:使用-sdk:minSdkVersion 14

android android-library android-studio

110
推荐指数
9
解决办法
34万
查看次数

在项目结构中找不到导入模块选项(Android Studio 0.3.4 - 0.5.2)

我真的很困惑和沮丧因为我无法理解如何导入我的android库项目作为我的应用程序项目的依赖项.

我尝试在线查找并建议大多数答案转到我的应用程序的项目结构,然后单击"+"然后单击"导入模块"

但Android Studio 0.3.4 - 0.5.2没有显示任何选项,当我点击"+"时,它只显示新模块的窗口.

我做错了什么或什么?

救命!!!

android android-library android-studio android-gradle-plugin

67
推荐指数
4
解决办法
4万
查看次数

需要另一个目录中的Gradle项目

我有一个像这样的目录/项目设置:

C:\
    _dev\
        Projects\
            Logger
            MyProject
Run Code Online (Sandbox Code Playgroud)

Logger是一个使用Gradle的Android库项目.MyProject是一个标准的Android项目项目,需要使用Logger库.

我正在使用Android Studio,并尝试将Logger添加到外部库.虽然这在开发过程中起作用,但我会在构建时收到有关未找到类的消息.

我是Gradle的新手,但在MyProject中的build.gradle中尝试了以下内容:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.0"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 18
    }

    dependencies {
        compile files("../Logger")
    }
}

dependencies {
    compile 'com.android.support:gridlayout-v7:18.0.0'
    compile 'com.android.support:appcompat-v7:18.0.0'
}
Run Code Online (Sandbox Code Playgroud)

java android multi-project gradle android-library

61
推荐指数
3
解决办法
5万
查看次数

如何跨多个项目共享单个库源

标题中的问题.这里提出一个类似的问题,唯一的解决方法是将项目发布到本地Maven存储库.

Android Studio 0.5中是否修复了此问题(如某些人所声称的那样).+?在其发行说明中,有一条声明说"支持模块内容根目录之外的源文件夹".这是否意味着我们最终可以从项目文件夹外部导入库?

我尝试了File-> Import Project ..但它不起作用.

编辑2:查看最新解决方案的已接受答案(截至0.8.+)

编辑:

我的项目目录结构只有一个模块main,如下所示

MyApp
    main
        build.gradle
        src
    build.gradle
    settings.gradle
Run Code Online (Sandbox Code Playgroud)

库项目目录只有一个名为like的模块lib(它们都是在创建新库项目时自动生成的)

MyLibrary
    lib
        build.gradle
        src
    build.gradle
    settings.gradle
Run Code Online (Sandbox Code Playgroud)

以下行添加到MyApp/settings.gradle:

include ':main', '..:MyLibrary'
Run Code Online (Sandbox Code Playgroud)

以下内容添加到MyApp/main/build.gradle:

dependencies {
    compile project(':..:MyLibrary')
}
Run Code Online (Sandbox Code Playgroud)

结果是以下错误:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':main'.
> Configuration with name 'default' not found.
Run Code Online (Sandbox Code Playgroud)

作为旁注,库项目MyLibrary本身可以编译而不会出错.问题似乎是settings.gradle无法识别图书馆项目结构.

android android-studio

59
推荐指数
2
解决办法
2万
查看次数

AndroidStudio - Gradle中的模块依赖项

我在使用Android Studio中的模块依赖项编译Android应用程序时遇到了一些问题.

所以,我希望我的应用程序使用库'slidingmenu'(链接在这里).

这是我的应用程序树:

  • 应用
  • slidingmenu(源文件)
  • slidingmenu-maps-support(源文件)

这是一个链接,看看我的意思.

这是我得到的错误.

Gradle:配置项目':Application'时出现问题.

无法通知项目评估监听器.

未找到名称"default"的配置.

如何指定模块依赖项以及在何处放置模块(在Application内部或ApplicationProject内部?

谢谢!

编辑1: 没关系!我回到了日食!Android Studio尚未准备好进行真正的项目开发.

android gradle slidingmenu android-studio

40
推荐指数
2
解决办法
7万
查看次数

如何将库项目添加到Android Studio并使用它?(有些人要求不生效)

如何将一个库项目添加到Android Studio并使用它?(有些问问题不会生效)我试着找到答案如何将一个库项目添加到Android Studio?如何使用Android Studio(不是jar)导入相关项目.但它不起作用.它还说"检索项目的父项时出错:找不到与给定名称'Theme.Sherlock.Light'匹配的资源." 等等

我的sdk工具rev是22.

android intellij-idea android-studio

18
推荐指数
2
解决办法
4万
查看次数

如何使用Android Studio和Gradle创建最佳的Android应用程序项目结构?

我正在尝试切换到Android Studio和Gradle,但是我在与Studio集成和使用Gradle构建时遇到了一些问题.

  • 我有一个依赖于几个库的应用程序.
  • 我想使用Android Studio和Gradle构建系统.
  • 我正在使用git
  • 我的大多数图书馆直接git clone来自他们的github位置

目前,我所拥有的是:

Main Project
 ??? GH Lib 1
 ?     ??? <some stuff from the lib>
 ?     ??? library
 ?           ??? AndroidManifest.xml
 ?           ??? res
 ?           ??? src
 ??? GH Lib 2
 ?     ??? <same structure as the lib 1>
 ??? GH Lib 3
 ?     ??? <same structure as the lib 1>
 ??? GH Lib 4
 ?     ??? <same structure as the lib 1>
 ??? My App folder
       ??? AndroidManifest.xml
       ??? res …
Run Code Online (Sandbox Code Playgroud)

android gradle android-studio

16
推荐指数
1
解决办法
1万
查看次数

Gradle无法为参数找到方法compile()

我有一个hello world全屏android studio 1.5.1应用程序,我添加了gradle/eclipse-mars子项目.除了将settings:'javalib'添加到settings.gradle之外,没有其他文件被修改.添加项目lib依赖项:

project(':app') {
    dependencies {
        compile project(':javalib') // line 23
    }
}
Run Code Online (Sandbox Code Playgroud)

从根构建构建文件并从命令行运行gradle,得到:

  • 其中:构建文件'D:\ AndroidStudioProjects\AndroidMain\build.gradle'行:23

  • 出了什么问题:评估根项目'AndroidMain'时出现问题.

    无法在org.grad le.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@46 3ca82f上为参数[project':javalib']找到方法compile().

将java插件添加到根构建文件没有帮助.

我不认为它在错误的地方.

根项目和添加的子项目都有gradle包装器.

任何指针将不胜感激.

谢谢

编辑:为了澄清,根构建文件是:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories …
Run Code Online (Sandbox Code Playgroud)

android subproject gradle android-gradle-plugin

11
推荐指数
1
解决办法
6万
查看次数

跨项目Android Studio共享自己的模块

从Eclipse迁移到Android Studio,我正在苦苦挣扎.

基本上,我认为Android Studio项目更像是工作空间,而模块更像项目......

但是,在Android Studio开始页面中,您只能创建项目,那么如何跨项目共享模块(即eclipse项目中的项目)?

基本上,我有许多使用我创建的共享库的应用程序,在Eclipse中我所做的就是将其标记为库,并在每个项目中只链接到它.

我完全不知道如何在Android Studio中执行此操作.除了在一个应用程序中使用模块之外,创建模块的示例似乎只会创建一个没有实际用途的模块.

我首先将我的库作为android studio中的项目导入,但事实证明这是无意义的,因为我希望它在我的版本控制系统中保持独立.

然后我在我的应用程序中创建了一个临时模块,但随后它将它存储在项目中,而在我的其他应用程序中,我找不到导入模块的方法,所以我真的看不到模块嵌入时的重点在项目中,不能在任何其他地方分开或引用.

谢谢你的帮助.

android-studio

7
推荐指数
1
解决办法
1493
查看次数