更新类路径后,我无法再构建应用程序的发布版本。
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':app:uploadCrashlyticsMappingFileRelease' (type 'UploadMappingFileTask').
- Type 'UploadMappingFileTask' property 'googleServicesResourceRoot' doesn't have a configured value.
Reason: This property isn't marked as optional and no value has been configured.
Possible solutions:
1. Assign a value to 'googleServicesResourceRoot'.
2. Mark property 'googleServicesResourceRoot' as optional.
A problem was found with the configuration of task ':app:uploadCrashlyticsMappingFileRelease' (type 'UploadMappingFileTask').
- Type 'UploadMappingFileTask' property 'googleServicesResourceRoot' doesn't have a …
Run Code Online (Sandbox Code Playgroud) 根据此文档,我们不再需要在 AndroidManifest.xml 中提供包名称,而是在 build.gradle 中使用命名空间,我们可以在其中定义包名称。
package="org.sample.domain" found in source AndroidManifest.xml: C:\Users\user\Desktop\Projects\Sample\app\libs\sample\src\main\AndroidManifest.xml.
Setting the namespace via a source AndroidManifest.xml's package attribute is deprecated.
Please instead set the namespace (or testNamespace) in the module's build.gradle file, as described here: https://developer.android.com/studio/build/configure-app-module#set-namespace
This migration can be done automatically using the AGP Upgrade Assistant, please refer to https://developer.android.com/studio/build/agp-upgrade-assistant for more information.
Run Code Online (Sandbox Code Playgroud)
但执行此操作后,“合并清单”选项卡会显示错误,指出我没有提供包名称。我同时尝试了两者,但警告版本再次显示。
android android-manifest android-studio android-gradle-plugin
由于从 Android 33 开始旧版本Activity.onBackPressed()
已被弃用,那么以编程方式调用它的更好方法是什么?
例子:
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
// Handle default back arrow click
android.R.id.home -> {
onBackPressed()
}
...
Run Code Online (Sandbox Code Playgroud)
我们可以创建并添加这样的OnBackPressedCallback
内容onBackPressedDispatcher
。
onBackPressedDispatcher.addCallback(
this, // Lifecycle owner
backPressedCallback
)
private val backPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (viewPager.currentItem != 0)
viewPager.setCurrentItem(0, true)
else
finish()
}
}
Run Code Online (Sandbox Code Playgroud)
然后将旧的替换onBackPressed
为
// Handle default back arrow click
android.R.id.home -> {
backPressedCallback.handleOnBackPressed()
}
Run Code Online (Sandbox Code Playgroud)
但我看到了这个公共方法onBackPressedDispatcher
,想知道是否可以用它来代替。
onBackPressedDispatcher.onBackPressed() …
Run Code Online (Sandbox Code Playgroud) android onbackpressed android-jetpack android-jetpack-navigation android-tiramisu
在实施 Firebase 的新应用程序检查功能时,我无法解决此问题。
将文件上传到 Firebase 存储时失败并出现错误
引起原因:java.io.IOException:{“错误”:{“代码”:401,“消息”:“Firebase应用程序检查令牌无效。” }}
我已经提供了调试秘密,就像本文档中的内容一样。
调试apk是通过USB调试直接安装的。
注意: 我使用的是物理设备,并在存储和实时数据库上启用了强制状态,每当我尝试执行上传等事务时,它都会失败,并显示上面的错误。
android firebase firebase-storage safetynet firebase-app-check
我在 RecyclerView 中遇到分页无限滚动的问题,我使用添加所有新项目.addAll()
movieList.addAll(it.movieList)
adapter.submitList(movieList)
Log.wtf("WTF", movieList.size.toString())
Run Code Online (Sandbox Code Playgroud)
每当我们从 API 获得成功响应时,大小就会不断增加,这表明列表确实正在填充,但 RecyclerView 中的项目保持不变,并且submitList()
似乎仅在第一次调用时才起作用。
这是我的 DiffUtil 类和适配器
class DiffUtilMovies : DiffUtil.ItemCallback<MovieItem>() {
// DiffUtil uses this test to help discover if an item was added, removed, or moved.
override fun areItemsTheSame(oldItem: MovieItem, newItem: MovieItem): Boolean {
return oldItem.id == newItem.id
}
// Check whether oldItem and newItem contain the same data; that is, whether they are equal.
// If there are differences between oldItem and newItem, this code tells …
Run Code Online (Sandbox Code Playgroud) android kotlin android-recyclerview android-diffutils android-listadapter
GlobalScope 和 MainScope 有什么区别?
//Accessing data from Room
GlobalScope.launch {
v.tvStoreName.text = pfViewModel.getStoreName()
pageDetails.pageNumber = currentPage
pageDetails.pageSize = pageSize
pfViewModel.getTransactions(pageDetails, toolbarBuilder?.getDate()!!)
}
Run Code Online (Sandbox Code Playgroud)
GlobalScope 有时会犯一个很难重现的错误。
致命异常:android.view.ViewRootImpl$CalledFromWrongThreadException:只有创建视图层次结构的原始线程才能触摸其视图。
MainScope().launch {
var storeName = ""
withContext(Dispatchers.Default) {
storeName = pfViewModel.getStoreName()
}
v.tvStoreName.text = storeName
}
Run Code Online (Sandbox Code Playgroud) 我一直在关注文档,但不幸的是它不包括使用材质组件作为应用程序整体主题时的适应。
<style name="Theme.App" parent="Theme.MaterialComponents.DayNight">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryVariant">@color/colorPrimaryDark</item>
<item name="colorOnPrimary">@android:color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/colorPrimary</item> <!--Fab color-->
<item name="colorOnSecondary">@color/colorAccent</item> <!--Fab icon color-->
<item name="colorSecondaryVariant">@color/colorAccentDark</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<!--<item name="tabStyle">@style/AppTabLayout</item>-->
<!-- The color for all other text including the menu -->
<item name="android:textColor">@color/colorPrimary</item>
<item name="android:textColorHighlight">@color/colorAccentDark</item>
<item name="android:windowAnimationStyle">@style/WindowAnimationTransition</item>
<item name="checkboxStyle">@style/AppCheckBoxStyle</item>
<item name="popupMenuBackground">@drawable/popup_bg_rounded</item>
<item name="materialAlertDialogTheme">@style/AppDialogTheme</item>
<item name="autoCompleteTextViewStyle">@style/AppCursor</item>
<item name="overlapAnchor">false</item>
<item name="android:dropDownVerticalOffset">?attr/actionBarSize</item>
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>
<style …
Run Code Online (Sandbox Code Playgroud) android material-components-android android-12 android-splashscreen
Android 12 中的新 API SplashScreen看起来不错,但就像之前文档中的示例代码一样,并没有真正帮助解释整个正确的实现。在某些情况下,您可能会在启动画面期间执行某些任务,在我们的情况下,这是启动 Firebase Auth,因此最好的方法可能只是选择不使用这个新的特色 API,但根据 lint 警告,它似乎是强制性的并且没有办法选择退出。
应用程序不应提供自己的启动屏幕
应用程序定义的启动画面从 Android 12 (API 31+) 开始,应用程序的启动画面由系统提供,应用程序不应创建自己的启动画面,否则用户将看到两个启动画面。请检查 SplashScreen 类以检查如何控制和自定义启动画面。
旧设备的向后兼容性如何,如何处理?是否有任何代码实验室项目可以玩和测试?
Firebase 控制台中的“云消息传递”部分是否已删除?我还尝试检查文档,但它只是将我重定向到 Firebase 控制台项目。
https://firebase.google.com/docs/cloud-messaging/js/send-with-console
这三个 Kotlin 插件有什么区别,它们的实际用途是什么?
plugins {
id 'kotlin-android'
id 'org.jetbrains.kotlin.android'
id "org.jetbrains.kotlin.jvm" version "1.6.20"
}
Run Code Online (Sandbox Code Playgroud)
第三种似乎是推荐的方式,特别是在使用Kotlin 协程时
假设我有一个包含 30 个项目的列表,并且给定索引为 9,我需要获取从索引 10 到 19 开始的项目。
目前正在以 Java 风格进行。
val newsList: ArrayList<Model> = arrayListOf()
// Get all items starting next to the current selected item
for (i in (position + 1) until originalList.size) {
// Limit the amount of item to avoid any possible OOM
if (newsList.size < 10)
newsList.add(list[i])
}
Run Code Online (Sandbox Code Playgroud) android ×7
kotlin ×4
firebase ×3
android-12 ×2
arraylist ×1
crashlytics ×1
material-components-android ×1
safetynet ×1