android - 如何将外部库项目添加到android studio 1.2.2?含溶液

标签 android android-studio android-support-library

我在 android studio 版本 1.2.2 中使用外部库项目时遇到问题。

我添加外部库项目的步骤是:-

  1. 我创建了一个新项目 exPagerSliding。

  2. 我在应用程序的根目录中添加一个新目录 (libs)。并将库粘贴到那里。

  3. 我打开我的应用程序 setting.gradle。并添加以下代码行

    include ':app' ':PagerSlidingTabStrip'
    project(':PagerSlidingTabStrip').projectDir=new File('libs/PagerSlidingTabStrip')
    
  4. 然后我打开我的 build.gradle 文件 添加以下代码行

    dependencies {
    classpath 'com.android.tools.build:gradle:1.2.3'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile project(":PagerSlidingTabStrip")
    }
    

5.接下来我转到 gradle.properties 并编写以下代码行。

    ANDROID_BUILD_MIN_SDK_VERSION=14
    ANDROID_BUILD_TARGET_SDK_VERSION=21
    ANDROID_BUILD_TOOLS_VERSION=21.1.3
    ANDROID_BUILD_SDK_VERSION=21
  1. 最后在 build.gradle 中添加

    安卓{

    compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION) buildToolsVersion 项目.ANDROID_BUILD_TOOLS_VERSION

            defaultConfig {
            minSdkVersion    Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
            targetSdkVersion     Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
        }
    

我收到一条消息“错误:无法获取空对象上的属性 ':PagerSlidingTabStrip'

当我从库中打开我的 build.gradle 文件时。他们我收到这条消息

你必须使用较新版本的android gradle插件。当前版本是1.0,推荐版本是1.2.3


好了,问题解决了,

所以我写给那些仍然面临这个烂摊子的人。

在 android studio 中使用外部库项目的步骤是:-

  1. 转到 file-new -import 模块。

  2. 选择您的库项目文件夹。

  3. 导入模块后。

  4. 转到文件->项目结构->选择应用程序->选择依赖项->单击右侧的+号->模块依赖项->选择您的模块名称并按确定。

    <
  5. 第四步是最后一步,但您可能会遇到两种类型的错误。前任。没有这样的属性组...为了处理这个去选择你的库的build.gradle,并删除像这样的行适用于:'https://raw.github.com/twotoasters/gradle-mvn-push/master/gradle-mvn-push.gradle'

最佳答案

这是我将外部库添加到 Android studio 项目的方式。

  1. 打开您要添加外部库的项目。
  2. 然后在 File> New> 中选择 Import new Module,导航到要添加到项目中的库项目,选择在项目中添加“库”模块。你会在你的项目 settings.gradle 旁边得到应用程序,包括库,是这样的:

    包括':app'、':library'

  3. 在 dependencies 部分添加 build.gradle(module :app) :

    编译项目(':library')

  4. 重建项目,仅此而已。

*您可以根据需要添加任意数量的库(模块)。在这种情况下,在 settings.gradle 中您将拥有:

 include ':app', ':lib1', ':lib2', ... 

build.gradle 中:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
//some your dependencies...

     compile project(':lib1')
    compile project(':lib2')
    ...
}

关于android - 如何将外部库项目添加到android studio 1.2.2?含溶液,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31238386/

相关文章:

android - 在 Android 中从 native c 返回 jbyteArray

android - 如何修复 'cmd package install-create -r -t -S 1699739' 返回错误 'Unknown failure: cmd: Can' t 查找服务 : package'

android - "cannot launch avd in emulator"

android - 属性 "background"已在 Android Studio 中使用不兼容的格式定义

android - 在 Eclipse 中,是否可以在使用 Android New Activity 向导时使用支持库

android - 如何使用支持库在android中滑动以删除cardview

android - android webview 中的阿拉伯字体?

android - 从Android Studio运行应用程序时出错

android - 更改PreferenceFragment的背景颜色

android - TooltipCompat 崩溃但我没有在我的代码中使用任何地方