简体   繁体   English

将库添加到 Android Studio 项目

[英]Add library to Android Studio project

I want to add this repository to my Android Studio project and I tried multiple dependencies but it just doesn't work.我想将此存储库添加到我的 Android Studio 项目中,并且尝试了多个依赖项,但它不起作用。 Any help, guys ?任何帮助,伙计们?

My build.gradle (app) file:我的 build.gradle (app) 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:24+'
    compile 'com.7heaven.widgets:segmentcontrol:1.16'
    compile 'at.bookworm:segcontrol:1' //THIS GUY IS MY PROBLEM
}

My build.gradle (app) file:我的 build.gradle (app) 文件:

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://jitpack.io"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
  1. Download the Library from Github.从 Github 下载库。
  2. Unzip.解压。
  3. In Android Studio go to File > New > Import Module and set the directory to "Library" folder inside "segcontrol-master".在 Android Studio 中,转到 File > New > Import Module 并将目录设置为“segcontrol-master”内的“Library”文件夹。

This worked out for me:这对我有用:

Open your project in Android Studio Download the library (using Git, or a zip archive to unzip) Go to File > Project Structure >Click on the more on the left green "+" button > import Module dependency in to your workplace.在 Android Studio 中打开您的项目 下载库(使用 Git 或 zip 存档解压缩)转到文件 > 项目结构 > 单击左侧绿色“+”按钮上的更多 > 将模块依赖项导入到您的工作区。 Then add that module to your project.然后将该模块添加到您的项目中。 Select "your Library"选择“你的图书馆”

What you want to achieve with this approach is to include a jCenter library via maven.你想用这种方法实现的是通过 maven 包含一个 jCenter 库。 But this repository is not uploaded to jCenter.但是这个仓库没有上传到jCenter。 You should be able to include the lib by downloading the sources and import the lib module or create a sysmlink to the libmodule in you project's root.您应该能够通过下载源代码并导入 lib 模块或在项目的根目录中创建指向 libmodule 的系统链接来包含 lib。

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

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