我已经在Android Studio 4.0.1中构建了一个应用程序。我的gradle脚本中的依赖项已全部自动生成,我不确定是否需要它们。当我在手机中运行该应用程序时,它显示为7MB。如果我评论gradle脚本的依赖项,则应用程序的大小将减小到3 MB,并且似乎可以正常工作。我可以只评论那些依赖吗?
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
最佳答案
是的,如果您想删除 UNUSED 依赖关系,则绝对有可能(并且很高兴)。如果您最终删除了应用程序中当前正在使用的任何依赖项,则将无法运行您的应用程序,因为它会引发编译错误,因为编译器将无法理解基于您依赖项的任何代码刚刚删除。
例如,如果您删除了约束布局的依赖关系,并且在项目中使用了约束布局,则不会编译您的应用程序。您可以在Google上搜索任何特定的依赖项,以决定您是否对项目使用了某些依赖项。
正如您在评论中所问的那样,以下依赖项用于测试您的应用程序,如果您不测试应用程序,则也可以将其删除。
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
关于android - 评论gradle依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63211755/