android - 使用 aar 在 Android Studio 上将 Git 库与项目包含在一起?

标签 android git module android-studio android-library

我是 Android Studio 的新手,一直无法弄清楚如何让这个库与我的应用一起工作。有人可以指导我如何在我的项目中安装和使用。我尝试将项目添加为模块,但它不像其他库/模块那样对我有用。

这是我要添加的项目:

https://github.com/rengwuxian/MaterialEditText

谢谢。

编辑:

构建.gradle

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

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':AndroidBootstrap')
compile project(':android-support-v4-preferencefragment-master')
compile project(':google-play-services_lib_lollipop')
compile 'com.rengwuxian.materialedittext:library:1.7.1'
}

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }



    // Move the tests to tests/java, tests/res, etc...
    instrumentTest.setRoot('tests')

    // Move the build types to build-types/<type>
    // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
    // This moves them out of them default location under src/<type>/... which would
    // conflict with src/ being used by the main source set.
    // Adding new build types or product flavors should be accompanied
    // by a similar customization.
    debug.setRoot('build-types/debug')
    release.setRoot('build-types/release')
}
}

最佳答案

我试过了,我只是添加了一行 compile 'com.rengwuxian.materialedittext:library:1.7.1' 在应用程序文件夹 build.gradle 中,这样

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.2'
    compile 'com.rengwuxian.materialedittext:library:1.7.1'
}

同步 gradle。然后,只需在布局 xml 中使用 com.rengwuxian.materialedittext.MaterialEditText 而不是 EditText,这样:

<com.rengwuxian.materialedittext.MaterialEditText
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="Basic"/>

MaterialEditText 直接继承了EditText,所以你不需要改变你的java代码。

编辑

build.gradle 在应用中

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.2'
    compile 'com.rengwuxian.materialedittext:library:1.7.1'
}

build.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.0.0-rc1'

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

allprojects {
    repositories {
        jcenter()
    }
}

设置.gradle

include ':app'

关于android - 使用 aar 在 Android Studio 上将 Git 库与项目包含在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27477385/

相关文章:

java - 有没有办法让 Timer.ScheduleAtFixedRate 更准确?

git - 将所有远程分支提取到裸 Git 存储库中

javascript - 从单独的文件调用 angular.module,找不到 Controller

c - 如何使用 fork() exec() 捕获 git clone 输出

git reset --hard 错误 : Could not parse object

java - 如何从 Intellij IDEA 中的类创建 .jar 库

java - Netbeans Java 模块交互

java - 无法获取 Retrofit 2 响应正文

java - 为什么 HttpURLConnection 的 getInputStream() 方法返回 RealBufferedSource 类型的对象?

Android Sensor Timestamp 引用时间