繁体   English   中英

如何使用android库作为我在项目应用中创建的模块?

[英]How do i use android library as module that i create in my project app?

我正在寻找一种方法来分离我正在创建的应用程序的代码。 这只是实验者,我不确定这是否是好事

我的项目结构如下所示

| --app

|

|-登录

在我的登录android库中,我只有两个输入字段,没有什么特别的登录屏幕。

那么,如何在我的应用程序项目中使用它?

我需要发布它才能将其用作网址吗? 或者我可以在内部使用它?

settings.gradle

include ':app', ':login'

登录librabry build.gradle

apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.1'
}

和应用程序build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.app.mandala"
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.1'
implementation project(':login')
}

而且我似乎无法在布局内的应用程序中包含登录库/模块。

在库build.gradle中替换以下行:

implementation fileTree(dir: 'libs', include: ['*.jar'])

api fileTree(dir: 'libs', include: ['*.jar'])

在您的应用程序build.gradle中,删除以下行:

implementation fileTree(include: ['*.jar'], dir: 'libs')

在布局xml中,您可能必须包含完整的程序包名称,例如<com.domain.project.CustomLoginView>

我不确定,但是我和你一样,但是我将库模块设置如下。 尝试将path:添加到build.gradle。 顺便说一句,如果要打开库,可以将其上载到远程存储库以进行共享。 但是,如果不这样做,则只能在项目中使用它。

implementation project(path: ':login')

暂无
暂无

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

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