简体   繁体   English

.app 域 package android 应用程序的名称

[英].app domain package name for android application

I have a.app domain registered and wanted to rename android application package with.app in the part, however after I changed the package name to.aap to.app view binding is not working and can't import R class我注册了一个 .app 域,想在部分中将 android 应用程序 package 重命名为 .app,但是在我将 package 名称更改为 .aap 到 .app 后,视图绑定不起作用并且无法导入 R class

There are two possible causes of this issue:此问题有两个可能的原因:

  1. Incorrect Import导入不正确
  2. Build cache issue.构建缓存问题。

Incorrect Import导入不正确

  • Generally, the ViewBinding classes are generated using the ApplicationID specified in AndroidManifest and build.gradle file.通常,ViewBinding 类是使用 AndroidManifest 和build.gradle文件中指定的 ApplicationID 生成的。
  • So, there is a chance, when you changed the application ID (aka packages), the import statements for those packages are not updated.因此,当您更改应用程序 ID(也称为包)时,有可能不会更新这些包的导入语句。
  • Just update those import statements with correct package names and you are good to go.只需使用正确的 package 名称更新这些导入语句,您就可以使用 go。

Build cache issue构建缓存问题

  • This is a common issue of build cache.这是构建缓存的常见问题。 Generally, the ViewBinding is created based on your Application ID specified in AndroidManifest and build.gradle file.通常,ViewBinding 是根据您在 AndroidManifest 和build.gradle文件中指定的应用程序 ID 创建的。

  • When you update the package name, the build cache is sometimes marked as dirty (ie invalid or expired).当您更新 package 名称时,构建缓存有时会被标记为脏(即无效或过期)。 Which doesn't allow you to access some auto generated classes like ViewBindings/DataBindings/Dependency injection classes.这不允许您访问一些自动生成的类,例如 ViewBindings/DataBindings/Dependency 注入类。

  • The only solution for this problem is performing a clean build as follow:此问题的唯一解决方案是执行干净的构建,如下所示:

    • In this Android Studion, from the menu click on Build -> Rebuild Project .在这个 Android Studion 中,从菜单中单击Build -> Rebuild Project
    • From terminal, in your project directory perform ./gradlew clean build .从终端,在您的项目目录中执行./gradlew clean build
  • In case your project build is failing, try to temporarily comment the code base causing the build failure and try above steps again.如果您的项目构建失败,请尝试暂时注释导致构建失败的代码库,然后重试上述步骤。 Once your build is successful, you can now revert back the commented changes.构建成功后,您现在可以恢复注释的更改。 (NOTE: While uncommenting the codebase, make sure import statements are correct, ie they are using the latest package name). (注意:取消注释代码库时,确保导入语句正确,即它们使用最新的 package 名称)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM