我创建了两个示例项目。现在我想将一个项目导入另一个项目。导入项目i的过程就像 -
new - > module->导入Gradle项目。
然后添加模块依赖
implementation project(':secondapp');
但我得到的错误就像 -
Error:Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :secondapp
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :secondapp
Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve project :secondapp
Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve project :secondapp
所以请告诉我什么是解决方案。我正在使用 Android studio 3.0 。
我的实际情况就像我有两个项目,我想将两个项目合并到第三个空项目中,这样我就不必管理2个应用程序,根据条件我可以启动任何一个Activity
项目。例如 -
if(firstProject){
startActivity(new Intent(thirdprojectActivty.this,firstprojectlaunchactivity.class));
}else{
startActivity(new Intent(thirdprojectActivty.this,secondprojectlaunchactivity.class));
}
那么告诉我这个场景可以通过将项目作为模块导入,或者这个场景还有其他解决方案吗?
答案 0 :(得分:0)
你可以通过将第3个项目中的2个项目作为模块导入并在build.gradle
文件中进行更改以作为库来使用。
compile project(':moduleaName')
要添加为库,请按以下步骤操作:
档案 - >项目结构 - >依赖关系 - >点击+图标 - >选择Module Dependnacies然后选择模块 - >点击确定 - >再次单击确定
希望得到这个帮助。
答案 1 :(得分:0)
正如 Imene Noomenefound 所提出的两种解决方案:
旧g radle-3.3的解决方案:
使用新g radle-4.1的解决方案:
distributionBase = GRADLE_USER_HOME distributionPath = wrapper / dists zipStoreBase = GRADLE_USER_HOME zipStorePath = wrapper / dists distributionUrl = https://services.gradle.org/distributions/gradle-4.1-all.zip
在项目的build.gradle文件中:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
//classpath 'me.tatarka:gradle-retrolambda:3.3.1' remove this line
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
In the file build.gradle of the app :
apply plugin: 'com.android.application'
//apply plugin: 'me.tatarka.retrolambda' remove this line
repositories {
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.imennmn.myprojectid"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
/**
* Enabling multidex support.
*/
multiDexEnabled true
missingDimensionStrategy 'minApi' , 'minApi24'
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
}
}
buildTypes {
release {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
/**
* Solve the problem when using multiple free source libs
* NOTICE or LICENSE files cause duplicates
*/
packagingOptions {
}
}
dependencies {
//your dependecies
}
在图书馆动画师升级build.gradle
的{{1}}到26:
targetSdkVersion