导入module报错:Unable to resolve dependency for ‘:app@debug/compileClasspath‘: Could not resolve

在项目中导入新module并添加依赖后遇到编译错误,尝试修改代理和调整编译版本未解决问题。最终发现是module的gradle配置错误,应用了错误的插件和设置了不应有的applicationId。修复方法是将apply plugin更改为'com.android.library',移除applicationId,调整后的配置使模块变为库项目,成功解决了编译问题。

     今天在项目中导入了一个module,然后再gradle中添加了依赖之后,编译报错。

    Unable to resolve dependency for ':app@debug/compileClasspath': Could not ***

    Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve

 

      一顿百度和google之后,最多的答案都是说修改代理,或者修改项目编译版本号。我找了我的gradle.properties文件,反复确定了,我没有添加代理。而且之前我创建项目和添加依赖包,也都没出现过这个问题。所以我就排除了代理的问题。

       然后我看了module的gradle文件,确认了下module的编译版本,和我项目的编译版本也是不冲突的。一时间我就有点蒙了,看来我的问题和别人的不一样啊。

      最后我看到了两个回答,一个带图片,很清晰的指出了问题所在,原来是module的gradle文件中的配置问题。  

      编译错误的module的gradle配置:

apply plugin: 'com.android.application'  //异常点

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {
       applicationId "com.ttxp"    //异常点
    }

 

 

问题就出在apply plugin和applicationId  因为module该把application改为library,而且不需要applicationId。修改后如下:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {

    }

 

然后重新编译就通过了。

{ "name": "vue-typescript-admin-template", "version": "0.1.0", "private": true, "author": "Chong Guo <armourcy@gmail.com>", "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "build:uat": "vue-cli-service build --mode production.uat", "lint": "vue-cli-service lint", "svg": "vsvg -s ./src/icons/svg -t ./src/icons/components --ext ts --es6", "test:e2e": "vue-cli-service test:e2e", "test:unit": "vue-cli-service test:unit" }, "dependencies": { "@types/echarts": "^4.4.6", "@types/webpack": "^4.41.12", "area-data": "^5.0.6", "axios": "^0.19.0", "echarts": "^5.3.2", "element-ui": "^2.12.0", "js-cookie": "^2.2.1", "md5": "^2.3.0", "moment": "^2.24.0", "normalize.css": "^8.0.1", "nprogress": "^0.2.0", "path-to-regexp": "^3.0.0", "register-service-worker": "^1.6.2", "vue": "^2.6.10", "vue-area-linkage": "^5.1.0", "vue-class-component": "^7.1.0", "vue-property-decorator": "^8.2.2", "vue-router": "^3.1.2", "vue-svgicon": "^3.2.6", "vuex": "^3.1.1", "vuex-class": "^0.3.2", "vuex-module-decorators": "^0.10.1", "vuex-persistedstate": "^2.7.0" }, "devDependencies": { "@types/jest": "^24.0.18", "@types/js-cookie": "^2.2.2", "@types/nprogress": "^0.2.0", "@types/webpack-env": "^1.14.0", "@vue/cli-plugin-babel": "^3.11.0", "@vue/cli-plugin-e2e-cypress": "^3.11.0", "@vue/cli-plugin-eslint": "^3.11.0", "@vue/cli-plugin-pwa": "^3.11.0", "@vue/cli-plugin-typescript": "^3.11.0", "@vue/cli-plugin-unit-jest": "^3.11.0", "@vue/cli-service": "^3.11.0", "@vue/eslint-config-standard": "^4.0.0", "@vue/eslint-config-typescript": "^4.0.0", "@vue/test-utils": "^1.0.0-beta.29", "babel-core": "^7.0.0-bridge.0", "babel-eslint": "^10.0.3", "eslint": "^6.2.2", "eslint-plugin-vue": "^5.2.3", "fibers": "^4.0.2", "jest": "^24.9.0", "sass": "^1.22.10", "sass-loader": "^7.3.1", "style-resources-loader": "^1.2.1", "ts-jest": "^24.0.2", "typescript": "3.6.2", "vue-cli-plugin-element": "^1.0.1", "vue-cli-plugin-style-resources-loader": "^0.1.3", "vue-template-compiler": "^2.6.10", "webpack": "^4.39.3" } } PS D:\My JAVA\苍穹外卖\前端源码\苍穹外卖前端源码\project-sky-admin-vue-ts> npm install npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: vue-typescript-admin-template@0.1.0 npm ERR! Found: vue@undefined npm ERR! node_modules/vue npm ERR! vue@"^2.6.10" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer vue@">=2.2.0" from vue-area-linkage@5.1.0 npm ERR! node_modules/vue-area-linkage npm ERR! vue-area-linkage@"^5.1.0" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See C:\Users\liuchaokun\AppData\Local\npm-cache\eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\liuchaokun\AppData\Local\npm-cache\_logs\2025-07-28T03_08_03_535Z-debug-0.log
07-29
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值