【问题标题】:Include Git Library with Project on Android Studio using aar?使用 aar 在 Android Studio 上的项目中包含 Git 库?
【发布时间】:2015-02-13 03:44:31
【问题描述】:

我是 Android Studio 的初学者,但不知道如何让这个库与我的应用程序一起工作。有人可以指导我如何在我的项目中安装和使用。我尝试将项目添加为模块,但这对我来说不像其他库/模块那样工作。

这是我要添加的项目:

https://github.com/rengwuxian/MaterialEditText

谢谢。

编辑:

build.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')
}
}

【问题讨论】:

    标签: android git module android-studio android-library


    【解决方案1】:

    我试过了,我只是添加了一行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'
    }
    

    Sync the 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()
        }
    }
    

    settings.gradle

    include ':app'
    

    【讨论】:

    • 当我添加 compile 'com.rengwuxian.materialedittext:library:1.7.1' 时它说找不到它,我需要做些什么来解决这个问题? @bjiang
    • 我对此没有意见。你的安卓工作室是什么版本的?您是否尝试创建一个新项目并添加它?
    • 我试图将其添加到现有项目中,您是下载 aar 文件并将其导入到 android studio(运行最新)还是下载整个项目并作为模块导入? @bjiang
    • 我的 settings.gradle 中没有任何内容,我将发布我所有的 gradle 文件。见编辑
    • 不在你的 main 中,它在你的 Root 中
    猜你喜欢
    • 2015-11-11
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 2018-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多