Android Studio 重复生成的文件
Posted
技术标签:
【中文标题】Android Studio 重复生成的文件【英文标题】:Android Studio duplicate generated files 【发布时间】:2020-02-10 09:36:52 【问题描述】:android Studio 不断创建生成的类,即使它们已经存在。
我猜这个问题与 NavigationArgs 有关,但它总是会产生一些重复错误。
现在解决我的问题的唯一方法是每次运行应用程序之前清理整个项目。
有谁知道如何解决这个问题,我怎么知道是哪个实现导致了这个错误?
Gradle 项目
buildscript
repositories
google()
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.google.gms:google-services:4.3.2'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0-beta01"
classpath ('com.google.firebase:firebase-plugins:1.1.0')
exclude group: 'com.google.guava', module: 'guava-jdk5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
allprojects
repositories
google()
jcenter()
maven url "https://jitpack.io"
task clean(type: Delete)
delete rootProject.buildDir
Gradle 模块
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: "androidx.navigation.safeargs"
android
compileSdkVersion 28
defaultConfig
applicationId "com.umbrella.budgetapp"
minSdkVersion 28
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
compileOptions
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.palette:palette:1.0.0'
implementation 'com.google.android.material:material:1.1.0-beta01'
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta05'
implementation 'androidx.viewpager:viewpager:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'com.github.ronaldsmartin:Material-ViewPagerIndicator:1.0.4'
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
implementation 'com.firebaseui:firebase-ui-firestore:5.0.0'
implementation 'com.google.firebase:firebase-auth:19.1.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.jakewharton:butterknife:10.2.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
implementation 'org.jetbrains:annotations:15.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.github.bumptech.glide:glide:4.10.0'
构建输出
> Task :app:compileDebugJavaWithJavac
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/buildConfig/debug/com/umbrella/budgetapp/BuildConfig 2.java:6: error: class BuildConfig is public, should be declared in a file named BuildConfig.java
public final class BuildConfig
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/buildConfig/debug/com/umbrella/budgetapp/BuildConfig.java:6: error: duplicate class: com.umbrella.budgetapp.BuildConfig
public final class BuildConfig
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/IconsDirections 4.java:9: error: class IconsDirections is public, should be declared in a file named IconsDirections.java
public class IconsDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/GoalDetailsDirections 6.java:9: error: class GoalDetailsDirections is public, should be declared in a file named GoalDetailsDirections.java
public class GoalDetailsDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/GoalsReachedDirections 4.java:16: error: class GoalsReachedDirections is public, should be declared in a file named GoalsReachedDirections.java
public class GoalsReachedDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/PlannedPaymentsDirections 4.java:16: error: class PlannedPaymentsDirections is public, should be declared in a file named PlannedPaymentsDirections.java
public class PlannedPaymentsDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/PlannedPaymentsDirections.java:16: error: duplicate class: com.umbrella.budgetapp.Layouts.Fragments.PlannedPaymentsDirections
public class PlannedPaymentsDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/GoalsReachedDirections.java:16: error: duplicate class: com.umbrella.budgetapp.Layouts.Fragments.GoalsReachedDirections
public class GoalsReachedDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/GoalsPausedDirections 4.java:16: error: class GoalsPausedDirections is public, should be declared in a file named GoalsPausedDirections.java
public class GoalsPausedDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/ShoppingListItemsArgs 4.java:13: error: class ShoppingListItemsArgs is public, should be declared in a file named ShoppingListItemsArgs.java
public class ShoppingListItemsArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/GoalsActiveDirections 5.java:16: error: class GoalsActiveDirections is public, should be declared in a file named GoalsActiveDirections.java
public class GoalsActiveDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/DebtsBorrowedDirections 5.java:16: error: class DebtsBorrowedDirections is public, should be declared in a file named DebtsBorrowedDirections.java
public class DebtsBorrowedDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/ShoppingItemsArgs 4.java:13: error: class ShoppingItemsArgs is public, should be declared in a file named ShoppingItemsArgs.java
public class ShoppingItemsArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/ShoppingListItemsDirections 4.java:16: error: class ShoppingListItemsDirections is public, should be declared in a file named ShoppingListItemsDirections.java
public class ShoppingListItemsDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/StatisticsBalanceDirections 7.java:9: error: class StatisticsBalanceDirections is public, should be declared in a file named StatisticsBalanceDirections.java
public class StatisticsBalanceDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/DebtsLentDirections 5.java:16: error: class DebtsLentDirections is public, should be declared in a file named DebtsLentDirections.java
public class DebtsLentDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/ShoppingListItemsArgs.java:13: error: duplicate class: com.umbrella.budgetapp.Layouts.Fragments.ShoppingListItemsArgs
public class ShoppingListItemsArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/ShoppingListsDirections 4.java:17: error: class ShoppingListsDirections is public, should be declared in a file named ShoppingListsDirections.java
public class ShoppingListsDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/GoalDetailsArgs 5.java:13: error: class GoalDetailsArgs is public, should be declared in a file named GoalDetailsArgs.java
public class GoalDetailsArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/GoalDetailsDirections.java:9: error: duplicate class: com.umbrella.budgetapp.Layouts.Fragments.GoalDetailsDirections
public class GoalDetailsDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/StatisticsCashflowDirections 4.java:9: error: class StatisticsCashflowDirections is public, should be declared in a file named StatisticsCashflowDirections.java
public class StatisticsCashflowDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/StoresDirections 4.java:16: error: class StoresDirections is public, should be declared in a file named StoresDirections.java
public class StoresDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/IconsDirections.java:9: error: duplicate class: com.umbrella.budgetapp.Layouts.Fragments.IconsDirections
public class IconsDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/Fragments/GoalsPausedDirections.java:16: error: duplicate class: com.umbrella.budgetapp.Layouts.Fragments.GoalsPausedDirections
public class GoalsPausedDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateUserProfileDirections 10.java:8: error: class UpdateUserProfileDirections is public, should be declared in a file named UpdateUserProfileDirections.java
public class UpdateUserProfileDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateDebtDirections 4.java:9: error: class UpdateDebtDirections is public, should be declared in a file named UpdateDebtDirections.java
public class UpdateDebtDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateAccountDirections 4.java:9: error: class UpdateAccountDirections is public, should be declared in a file named UpdateAccountDirections.java
public class UpdateAccountDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateCategoryArgs 6.java:13: error: class UpdateCategoryArgs is public, should be declared in a file named UpdateCategoryArgs.java
public class UpdateCategoryArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateCategoryDirections 4.java:9: error: class UpdateCategoryDirections is public, should be declared in a file named UpdateCategoryDirections.java
public class UpdateCategoryDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateGoalDetailsDirections 9.java:8: error: class UpdateGoalDetailsDirections is public, should be declared in a file named UpdateGoalDetailsDirections.java
public class UpdateGoalDetailsDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateGoalDetailsDirections 10.java:8: error: class UpdateGoalDetailsDirections is public, should be declared in a file named UpdateGoalDetailsDirections.java
public class UpdateGoalDetailsDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdatePlannedPaymentArgs 8.java:13: error: class UpdatePlannedPaymentArgs is public, should be declared in a file named UpdatePlannedPaymentArgs.java
public class UpdatePlannedPaymentArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateGoalDetailsArgs 8.java:14: error: class UpdateGoalDetailsArgs is public, should be declared in a file named UpdateGoalDetailsArgs.java
public class UpdateGoalDetailsArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateCurrencyDirections 7.java:9: error: class UpdateCurrencyDirections is public, should be declared in a file named UpdateCurrencyDirections.java
public class UpdateCurrencyDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateTemplateArgs 7.java:13: error: class UpdateTemplateArgs is public, should be declared in a file named UpdateTemplateArgs.java
public class UpdateTemplateArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdatePlannedPaymentArgs 9.java:13: error: class UpdatePlannedPaymentArgs is public, should be declared in a file named UpdatePlannedPaymentArgs.java
public class UpdatePlannedPaymentArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateGoalDetailsArgs 9.java:14: error: class UpdateGoalDetailsArgs is public, should be declared in a file named UpdateGoalDetailsArgs.java
public class UpdateGoalDetailsArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateDebtDirections.java:9: error: duplicate class: com.umbrella.budgetapp.Layouts.UpdateFragments.UpdateDebtDirections
public class UpdateDebtDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateGoalSelectDirections 9.java:16: error: class UpdateGoalSelectDirections is public, should be declared in a file named UpdateGoalSelectDirections.java
public class UpdateGoalSelectDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateStoreArgs 7.java:13: error: class UpdateStoreArgs is public, should be declared in a file named UpdateStoreArgs.java
public class UpdateStoreArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateAccountArgs 7.java:13: error: class UpdateAccountArgs is public, should be declared in a file named UpdateAccountArgs.java
public class UpdateAccountArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdatePlannedPaymentDirections 7.java:9: error: class UpdatePlannedPaymentDirections is public, should be declared in a file named UpdatePlannedPaymentDirections.java
public class UpdatePlannedPaymentDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateUserProfileDirections 8.java:8: error: class UpdateUserProfileDirections is public, should be declared in a file named UpdateUserProfileDirections.java
public class UpdateUserProfileDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateRecordDetailsDirections 9.java:8: error: class UpdateRecordDetailsDirections is public, should be declared in a file named UpdateRecordDetailsDirections.java
public class UpdateRecordDetailsDirections
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateDebtArgs 9.java:13: error: class UpdateDebtArgs is public, should be declared in a file named UpdateDebtArgs.java
public class UpdateDebtArgs implements NavArgs
^
/Users/XX/Documents/AndroidStudio/Projects/BudgetApp/app/build/generated/source/navigation-args/debug/com/umbrella/budgetapp/Layouts/UpdateFragments/UpdateShoppingListDirections 9.java:9: error: class UpdateShoppingListDirections is public, should be declared in a file named UpdateShoppingListDirections.java
public class UpdateShoppingListDirections
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
100 errors
> Task :app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
【问题讨论】:
我也有同样的问题 我只是在切换风格时删除了生成的文件夹作为解决方法。我已向导航开发人员提交了有关此问题的错误。 【参考方案1】:选项 1:
请删除文件夹
点击 assembleDebug 后删除文件夹:
执行此命令后AssembleDebug你会得到你的错误。
选项 2:
按照以下说明解决。
项目级 build.gradle
使用
maven url "https://www.jitpack.io"
而不是
maven url "https://jitpack.io"
【讨论】:
没有解决问题,抱歉:/ 试试这个:选项 2 像魔术一样为我工作......但我删除了两个文件夹“.gradle”和“build”然后正常运行应用程序,它会自动重新生成文件夹,从而删除重复实例 您能否解释一下选项 2 是如何解决问题的?我得到同样的问题。选项 1 临时修复它,但在 2-3 次构建后它开始重新出现。 同样的问题,尝试了很多东西。没有布宜诺【参考方案2】:进入菜单并选择:Build -> Clean Project,完成后,Build -> Rebuild project
【讨论】:
【参考方案3】:如果点击 Build -> Clean project 或 Rebuild project 不能解决这个问题,应该有另一个问题导致构建失败。修复其他问题,重建可能会成功。
还要检查包中是否存在真实的BuildConfig文件,删除后重试。
【讨论】:
以上是关于Android Studio 重复生成的文件的主要内容,如果未能解决你的问题,请参考以下文章
Android Studio中的proguard映射文件在哪里[重复]
使用 Android Studio 生成发布 SHA1 证书 [重复]