Gradle 无法解析项目:linkedin-sdk
Posted
技术标签:
【中文标题】Gradle 无法解析项目:linkedin-sdk【英文标题】:Gradle could not resolve project :linkedin-sdk 【发布时间】:2017-12-03 10:58:33 【问题描述】:我正在使用 Androis Studio 3.0 Canary 4。在我的项目中,我有 Linkedin-sdk,它可以工作。我可以使用它。唯一的问题是当我搜索构建 Gradle 时收到此消息。
因为我无法构建它,所以我无法使用设计编辑器和预览。
这是我的 build.gradle 项目:
buildscript
repositories
jcenter()
maven url 'https://maven.google.com'
dependencies
classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
classpath 'com.google.gms:google-services:3.0.0'
allprojects
repositories
jcenter()
maven
url 'https://maven.google.com'
task clean(type: Delete)
delete rootProject.buildDir
Build.Gradle 模块:应用程序
apply plugin: 'com.android.application'
android
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig
applicationId "com.cving_team.cving"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
signingConfigs ...
buildTypes
sdkTest
signingConfig signingConfigs.sdkTest
debuggable true
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
signingConfig signingConfigs.release
dependencies
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-
core:2.2.2',
exclude group: 'com.android.support', module: 'support-annotations'
)
compile project(':retrofit-2.1.0')
compile project(':linkedin-sdk')
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:appcompat-v7:26.0.0-beta2'
compile 'com.android.support:customtabs:26.0.0-beta2'
compile 'com.android.support:design:26.0.0-beta2'
compile 'com.android.support:cardview-v7:26.0.0-beta2'
compile 'com.android.support:recyclerview-v7:26.0.0-beta2'
compile 'com.facebook.android:facebook-android-sdk:4.24.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.mutualmobile.android:cardstack:0.5.2'
compile 'com.google.android.gms:play-services-location:11.0.1'
compile 'com.google.android.gms:play-services-places:11.0.1'
compile 'com.squareup.okhttp3:okhttp:3.7.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
compile 'eu.davidea:flexible-adapter:5.0.0-rc1'
compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
compile 'com.google.firebase:firebase-core:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
testCompile 'junit:junit:4.12'
apply plugin: 'com.google.gms.google-services'
Linkedin-sdk 在 settings.gradle 中。
include ':app', ':retrofit-2.1.0', ':fabby-sdk-jni', ':linkedin-sdk'
可能是什么问题?
更新
我已从终端启动此命令:gradlew tasks,并收到此错误:
> Configure project :app
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
Configuration 'androidTestCompile' in project ':app' is deprecated. Use 'androidTestImplementation' instead.
Configuration 'testCompile' in project ':app' is deprecated. Use 'testImplementation' instead.
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
> Configure project :fabby-sdk-jni
Configuration 'compile' in project ':fabby-sdk-jni' is deprecated. Use 'implementation' instead.
Configuration 'androidTestCompile' in project ':fabby-sdk-jni' is deprecated. Use 'androidTestImplementation' instead.
Configuration 'testCompile' in project ':fabby-sdk-jni' is deprecated. Use 'testImplementation' instead.
> Configure project :linkedin-sdk
Configuration 'compile' in project ':linkedin-sdk' is deprecated. Use 'implementation' instead.
Configuration 'androidTestCompile' in project ':linkedin-sdk' is deprecated. Use 'androidTestImplementation' instead.
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:testSdkTestUnitTest'.
> Could not resolve all task dependencies for configuration ':app:sdkTestUnitTestRuntimeClasspath'.
> Could not resolve project :linkedin-sdk.
Required by:
project :app
> Unable to find a matching configuration of project :linkedin-sdk:
- Configuration 'debugApiElements':
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttrname=Aar' and found compatible value 'AndroidTypeAttrname=Aar'.
- Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttrname=sdkTest' and found incompatible value 'BuildTypeAttrname=debug'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttrname=debug' but wasn't required.
- Required org.gradle.api.attributes.Usage 'for runtime' and found incompatible value 'for compile'.
- Configuration 'debugRuntimeElements':
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttrname=Aar' and found compatible value 'AndroidTypeAttrname=Aar'.
- Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttrname=sdkTest' and found incompatible value 'BuildTypeAttrname=debug'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttrname=debug' but wasn't required.
- Required org.gradle.api.attributes.Usage 'for runtime' and found compatible value 'for runtime'.
- Configuration 'releaseApiElements':
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttrname=Aar' and found compatible value 'AndroidTypeAttrname=Aar'.
- Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttrname=sdkTest' and found incompatible value 'BuildTypeAttrname=release'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttrname=release' but wasn't required.
- Required org.gradle.api.attributes.Usage 'for runtime' and found incompatible value 'for compile'.
- Configuration 'releaseRuntimeElements':
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttrname=Aar' and found compatible value 'AndroidTypeAttrname=Aar'.
- Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttrname=sdkTest' and found incompatible value 'BuildTypeAttrname=release'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttrname=release' but wasn't required.
- Required org.gradle.api.attributes.Usage 'for runtime' and found compatible value 'for runtime'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
已解决
只是改变:
compile project(':linkedin-sdk')
到
compile project(path: ':linkedin-sdk', configuration: 'default')
【问题讨论】:
你能出示你的settings.gradle
吗?
就像我之前说的已经包含在内。已更新。
你在app/
中没有第二个settings.gradle
,是吗?
如果您从命令行构建,是否会发生同样的错误?
不,我没有。我没有尝试从命令行构建。试着告诉你
【参考方案1】:
由于您使用的是新的 android 插件 3.x,因此您必须关注migration guidelines:
错误:无法解析:无法解析项目:linkedin-sdk。
要解决此错误,您需要从“mylibrary”(在您的情况下为linkedin-sdk)中指定 Android 插件应与应用的“暂存”构建类型匹配的构建类型。您可以使用应用程序的build.gradle
文件中的buildTypeMatching
属性来执行此操作,如下所示:
android
...
// Tells the Android plugin to use a library's 'debug' build type
// when a 'staging' build type is not available. You can include
// additional build types, and the plugin matches 'staging' to the
// first build type it finds from the one's you specify. That is,
// if 'mylibrary' doesn't include a 'debug' build type either, the
// plugin matches 'staging' with the producer's 'release' build type.
buildTypeMatching 'staging', 'debug', 'release'
编辑:
buildTypeMatching
was replacedmatchingFallbacks
.
您可以找到有关变体感知依赖管理的更多信息
here 和 here。
android
buildTypes
debug
release
staging
// Specifies a sorted list of fallback build types that the
// plugin should try to use when a dependency does not include a
// "staging" build type. You may specify as many fallbacks as you
// like, and the plugin selects the first build type that's
// available in the dependency.
matchingFallbacks = ['debug', 'qa', 'release']
然后
找不到项目的匹配配置:linkedin-sdk:
你可以使用
compile project(path: ':linkedin-sdk', configuration: 'default')
但您可以简单地使用以下内容来利用变量感知依赖解析。 .
implementation project(':linkedin-sdk')
您可以在有关新依赖项configurations
的部分中了解有关'implementation'
配置的更多信息。
【讨论】:
我在 android 3.2 中将它用于多模块地理围栏、聊天和工作...谢谢 这似乎在较新的 gradle 版本中被删除 - 现在应该按照 this related answer 定义“后备”构建类型 你是通过jar库还是lib导入linkedln sdk。项目?Gradle DSL method not found: 'buildTypeMatching()'
@m0skit0 buildTypeMatching 已替换为带有插件 3.0 beta4 的 matchFallbacks。你可以在这里找到更多信息:developer.android.com/studio/build/dependencies#variant_aware 和这里:developer.android.com/studio/build/…【参考方案2】:
我已经解决了我的问题。在 build.gradle(Module app) buildTypes
必须有这个结构:
buildTypes
debug
releaseApp
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
releaseSdk
signingConfig signingConfigs.sdkTest
debuggable true
并且在 build.gradle(Module linkedinn-sdk) buildTypes 必须具有相同的结构。所以新代码是:
buildTypes
debug
releaseApp
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
releaseSdk
【讨论】:
差不多一年后,这仍然是最好的答案。跨模块的 buildTypes 需要具有相同的类型。【参考方案3】:我遇到了类似的错误,但我能够解决:
21:13 Gradle sync failed: Cannot choose between the following configurations of project :sTLivenessLibrary:
- debugApiElements
- debugRuntimeElements
- releaseApiElements
- releaseRuntimeElements
All of them match the consumer attributes:
- Configuration 'debugApiElements':
- Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
- Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
- Found org.gradle.api.attributes.Usage 'for compile' but wasn't required.
- Configuration 'debugRuntimeElements':
- Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required.
- Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
我通过更改编译配置解决了这个问题:
compile project(':linkedin-sdk')
到
compile project(path: ':linkedin-sdk', configuration: 'default').
【讨论】:
【参考方案4】:是的
implementation project(path: ':linkedin-sdk', configuration: 'default')
有效
您可以在左侧标签Build Variants
【讨论】:
【参考方案5】:我在更新到 android studio 3.0 时也遇到了这个问题
这是我在 app gradde 文件中的构建类型块
buildTypes
staging
buildConfigField 'String', 'HOST', '"http://compute.amazonaws.com/"'
buildConfigField 'String', 'REGION_CODE', '"1"'
debuggable true
signingConfig signingConfigs.debug
QA
buildConfigField 'String', 'HOST', '"com.amazo/"'
buildConfigField 'String', 'REGION_CODE', '"92"'
debuggable true
signingConfig signingConfigs.debug
notificationTest
buildConfigField 'String', 'HOST', '"http://a6a"'
buildConfigField 'String', 'REGION_CODE', '"92"'
debuggable true
signingConfig signingConfigs.debug
这是我的项目依赖项
compile project(':slideDateTimePicker')
compile project(':scatter')
我打开了 scatter build.gradle 和 slideDateTimePicker build.gradle 文件并用这个替换了 android 块。
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
QA
notificationTest
releaseApp
releaseSdk
staging
【讨论】:
【参考方案6】:您需要将 LinkedIn SDK 作为一个模块导入到您的 Android Studio 项目中。为此
-
从您从 LinkedIn 下载的 ZIP 文件中提取项目。
在 Android Studio 菜单中,导航到 Android 文件 -> 新建 -> 导入模块,然后选择您在步骤 1 中创建的文件夹。
来源:https://***.com/a/38998826/1440565
【讨论】:
就像我在问题上所说的那样,我已经解决了这个问题。并且linkedin sdk一如既往地工作。这不是进口问题。这只是 Gradle 的一个错误。以下是更多信息:***.com/questions/44114044/…以上是关于Gradle 无法解析项目:linkedin-sdk的主要内容,如果未能解决你的问题,请参考以下文章
Spring Boot 多项目 Gradle --> 主类名未配置,无法解析
Eclipse 和 Gradle 类路径不同步:无法解析为类型
Build.gradle无法解析com.android.support
> 无法解析 com.android.tools.build:gradle:3.5.0
Android Studio:从 Github 导入项目并使用 gradle 文件重建/清理/同步后“无法解析符号 R”