Android Studio新建Project或Module报Failed to resolve:com.android.support:appcompat-v7:27.+ 错误

本文针对构建新项目时出现的appcompat-v7包缺失问题提供了三种解决方案。问题源于Android Studio使用Gradle构建项目时默认采用最高SDK版本,导致部分依赖不匹配。文章欢迎读者分享更多解决思路。

如题:错误信息提示找不到匹配的appcompat-v7包;

重新下载V7包还是无法解决此问题,只好在网上翻了翻,经过本人的验证找到了三种解决方案,欢迎大家指正

第一种

第二种

第三种

构建新的项目时,android studio使用gradle对项目进行构建,gradle会按照你最高的sdk构建工具版本构建,所以会出现此问题,如有其它解决方案或想法,欢迎大家提出.

AILURE: Build completed with 3 failures. 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:compileDebugCoverageUnitTestJavaWithJavac'. > Could not resolve all files for configuration ':app:debugCoverageUnitTestCompileClasspath'. > Could not find org.mockito:mockito-inline:5.4.0. Required by: project :app > Could not find org.robolectric:androidx-support-v4:4.10.3. Required by: project :app > Could not find org.robolectric:androidx-core:4.10.3. Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:compileDebugUnitTestJavaWithJavac'. > Could not resolve all files for configuration ':app:debugUnitTestCompileClasspath'. > Could not find org.mockito:mockito-inline:5.4.0. Required by: project :app > Could not find org.robolectric:androidx-support-v4:4.10.3. Required by: project :app > Could not find org.robolectric:androidx-core:4.10.3. Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== 3: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:compileReleaseUnitTestJavaWithJavac'. > Could not resolve all files for configuration ':app:releaseUnitTestCompileClasspath'. > Could not find org.mockito:mockito-inline:5.4.0. Required by: project :app > Could not find org.robolectric:androidx-support-v4:4.10.3. Required by: project :app > Could not find org.robolectric:androidx-core:4.10.3. Required by: project :app * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings BUILD FAILED in 20s 81 actionable tasks: 81 executed apply plugin: 'jacoco' tasks.withType(Test) { jacoco.includeNoLocationClasses = true jacoco.excludes = ['jdk.internal.*'] } configurations { jacocoAnt jacocoRuntime } jacoco { toolVersion = "0.8.5" } def offline_instrumented_outputDir = "$buildDir.path/intermediates/classes-instrumented/debugCoverage" tasks.withType(Test) { jacoco.includeNoLocationClasses = true jacoco.excludes = ['jdk.internal.*'] } def coverageSourceDirs = [ 'src/main/java' ] task jacocoTestReport(type: JacocoReport, dependsOn: "test") { group = "Reporting" description = "Generate Jacoco coverage reports" classDirectories.from = fileTree( dir: './build/intermediates/javac/debugCoverage/classes/', excludes: [ '**/R.class', '**/R$*.class', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*', '**/BuildConfig.*', '**/**Bean.class', '**/inputmethod/*', '**/config/*.*', '**/flex/*.*', '**/AssetsUtils.class' ] ) getSourceDirectories().setFrom(files(coverageSourceDirs)) getExecutionData().setFrom(files('./build/jacoco/testDebugUnitTest.exec')) } jacocoTestReport { reports { xml.enabled true html.enabled true html.destination file("build/test-results/jacocoHtml") } } task createOfflineTestCoverageReport(dependsOn: ['instrument', 'testDebugCoverageUnitTest']) { group = "reporting" doLast { ant.taskdef(name: 'report', classname: 'org.jacoco.ant.ReportTask', classpath: configur3+ations.jacocoAnt.asPath) ant.report() { executiondata { ant.file(file: "$buildDir.path/jacoco/testDebugCoverageUnitTest.exec") } structure(name: 'Example') { classfiles { fileset(dir: "$project.buildDir/intermediates/javac/debugCoverage") } sourcefiles { fileset(dir: 'src/main/java') } } } } } createOfflineTestCoverageReport.dependsOn(clean) gradle.taskGraph.whenReady { graph -> if (graph.hasTask(instrument)) { tasks.withType(Test) { doFirst { systemProperty 'jacoco-agent.destfile', buildDir.path + '/jacoco/testDebugCoverageUnitTest.exec' classpath = files(offline_instrumented_outputDir) + classpath + configurations.jacocoRuntime } } } } task instrument(dependsOn:'compileDebugUnitTestSources') { doLast { println 'Instrumenting classes' ant.taskdef(name: 'instrument', classname: 'org.jacoco.ant.InstrumentTask', classpath: configurations.jacocoAnt.asPath) ant.instrument(destdir: offline_instrumented_outputDir) { fileset(dir: "$buildDir.path/intermediates/javac/debugCoverage") } } } plugins { id 'com.android.application' } apply from: 'jacoco-report.gradle' android { signingConfigs { debug { storeFile file('./keystore/platform.jks') storePassword '123456' keyPassword '123456' keyAlias 'ktplatfrom' } } compileSdk 32 defaultConfig { applicationId "com.st.manual" minSdk 21 targetSdk 32 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } debugCoverage { minifyEnabled false testCoverageEnabled false } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } applicationVariants.all { variant -> variant.outputs.all { output -> outputFileName = "ktUserManual.apk" } } dataBinding{ enabled = true } testOptions { unitTests { includeAndroidResources = true returnDefaultValues = true all { systemProperty 'robolectric.logging.enabled', 'true' systemProperty 'robolectric.ignoreMissingApplication', 'true' } } } defaultConfig{ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } } dependencies { implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.google.android.material:material:1.8.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' // testImplementation 'junit:junit:4.13.2' // ----------------------------------------------------- // 新增测试依赖 testImplementation 'junit:junit:4.13.2' // Mockito 5.x 支持 mockStatic 和 new 操作 testImplementation 'org.mockito:mockito-core:5.4.0' testImplementation 'org.mockito:mockito-inline:5.4.0' // Robolectric 测试 AndroidX 支持 testImplementation 'org.robolectric:robolectric:4.10.3' testImplementation 'org.robolectric:androidx-support-v4:4.10.3' testImplementation 'org.robolectric:androidx-core:4.10.3' // testImplementation 'junit:junit:4.13.2' // testImplementation 'androidx.test.ext:junit:1.1.4' // testImplementation 'androidx.test.espresso:espresso-core:3.5.0' // // test // testImplementation 'androidx.test:runner:1.6.2' // testImplementation 'androidx.test.ext:junit:1.2.1' // // testImplementation 'androidx.fragment:fragment-testing:1.6.2' // testImplementation 'androidx.test:core:1.4.0' // // // todo test 依赖 // testImplementation 'org.robolectric:robolectric:4.8' // testImplementation 'androidx.test:rules:1.6.1' // testImplementation 'org.powermock:powermock-module-junit4:2.0.7' // testImplementation 'org.powermock:powermock-module-junit4-rule:1.7.4' // testImplementation 'org.powermock:powermock-api-mockito2:2.0.7' // testImplementation 'org.mockito:mockito-core:3.3.3' // testImplementation 'android.arch.core:core-testing:1.1.1' // testImplementation 'org.mockito:mockito-inline:3.11.2' } 请问应该怎么处理
最新发布
07-25
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值