已经有无数的文章介绍了如何从使用 groovy 脚本迁移到使用 Kotlin DSL 进行 Gradle 依赖管理是管理构建脚本的理想方式以及其他提到的优势。
但是,我发现的限制是缺乏这种 Gradle 管理方式或流程,无法像以前使用 groovy 脚本那样突出显示当前依赖项的新版本可用时的情况。我发现的当前解决方案包括使用插件或实用程序扫描您的 buildSrc 文件夹并将更新作为对当前版本库的注释提供。其中一些包括以下内容:
除了我提到的几个插件之外,还有其他有效的方法来检查依赖项更新吗?
android android-studio android-gradle-plugin gradle-kotlin-dsl
大小为 4 的a 的内容Byte Array如下:
{1, 0, 0, 0}。1使用时这会转换为 C# 中的整数BitConverter.ToInt32(bytearray, 0);
但是,当Integer使用以下代码库将此字节数组转换为 Kotlin 中的 时,我得到的是值16777216而不是 的值1。
var test0 = BigInteger(bytearray).toInt() = 16777216
var test1 = BigInteger(bytearray).toFloat() = 1.6777216
Run Code Online (Sandbox Code Playgroud)
或者
fun toInt32(bytes: ByteArray, index: Int): Int
{
if (bytes.size != 4)
throw Exception("The length of the byte array must be at least 4 bytes long.")
return 0xff
and bytes[index].toInt() shl 56
or (0xff and bytes[index + 1].toInt() shl …Run Code Online (Sandbox Code Playgroud) 我使用recyclerview显示项目列表,约束布局是父视图.布局显示如下:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<!-- Load the toolbar here -->
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?android:attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@color/colorPrimary"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:visibility="visible"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
<ImageView
android:id="@+id/imageViewContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="parent"
android:visibility="gone"
android:src="@drawable/empty_category"/>
<TextView
android:id="@+id/textViewContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="Empty Category"
android:textStyle="bold"
android:textColor="@color/colorPrimary"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageViewContent" />
</android.support.constraint.ConstraintLayout>
The adapter layout for each row is presented below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> …Run Code Online (Sandbox Code Playgroud) 我的gradle.properties.kts文件有以下内容:
build_version=develop
build_version_code=2
include_vas=false
Run Code Online (Sandbox Code Playgroud)
在我的build.gradle.kts中如下所示:
plugins {
id(Plugins.androidApplication)
kotlin(Plugins.kotlinAndroid)
kotlin(Plugins.kotlinExtensions)
kotlin(Plugins.kapt)
}
android {
compileSdkVersion(Configs.compileVersion)
defaultConfig {
applicationId = Configs.applicationId
minSdkVersion(Configs.minSdkVersion)
targetSdkVersion(Configs.targetSdkVersion)
testInstrumentationRunner = Configs.testInstrumentationRunner
versionCode =
}
buildTypes{
}
repositories {
flatDir {
dirs("libs")
}
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.arr"))))
implementation(Libs.stdLib)
implementation(Libs.sunmiui)
implementation(Libs.slf4j)
implementation(Libs.appCompact)
implementation(Libs.otpView)
implementation(Libs.vectordrawableAnimated)
implementation(Libs.materialComponents)
implementation(Libs.recyclerView)
implementation(Libs.constraintLayout)
implementation(Libs.junit)
implementation(Libs.testRunner)
implementation(Libs.expressoCore)
implementation(Libs.lifecyleExtensions)
implementation(Libs.lifecyleCompiler)
implementation(Libs.roomRuntime)
implementation(Libs.databindingCompiler)
implementation(Libs.rxjava)
implementation(Libs.rxjavaAndroid)
implementation(Libs.glide)
implementation(Libs.glideCompiler)
implementation(Libs.gson)
implementation(Libs.joda)
implementation(Libs.countrycodePicker)
implementation(Libs.timber)
implementation(Libs.daggerandroidSupport)
implementation(Libs.daggerandroidProcessor)
}
Run Code Online (Sandbox Code Playgroud)
我正在将我当前的 gradle 脚本转换为 …
如何使用回收器视图为Features和Rules下的元素创建水平滚动?
我知道对于属性类型和房间数,我可以使用两个单独的回收器视图。但是,我是否需要创建两个回收器视图来显示这些元素,因为文本元素的长度将是不均匀的,并且如果添加更多规则和功能来满足不断扩展的项目列表?
android horizontal-scrolling horizontalscrollview android-recyclerview
我已经在我的android应用程序中实现了底部导航视图。带有五个片段。但是,我有一个问题,每次更改片段时,片段的内容都会与工具栏重叠。
底部导航视图的布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DashboardActivity">
<include layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</include>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_above="@+id/navigationView"
android:layout_height="match_parent"
/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigationView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:itemBackground="@android:color/white"
app:itemIconTint="@color/cardview_dark_background"
app:itemTextColor="@android:color/black"
app:menu="@menu/navigation_menu"
/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
片段布局之一的示例
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AttendanceFragment">
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.7" />
<android.support.v7.widget.CardView
android:id="@+id/cardView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/barrier3"
app:layout_constraintEnd_toStartOf="@+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Spinner
android:id="@+id/spinner_courses"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:paddingBottom="4dp"
android:paddingTop="4dp"
app:layout_constraintEnd_toStartOf="@+id/guideline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.v7.widget.CardView>
<TextView
android:id="@+id/tv_time" …Run Code Online (Sandbox Code Playgroud) 在Gradle脚本中更新build.gradle(Module:app)中的依赖项之后,我的所有布局,字符串,R定义的所有引用都不可用.我在Module app中有以下代码:
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex')) {
details.useVersion "28.0.0"
}
if(details.requested.group == 'androidx.lifecycle' && !details.requested.name.contains('multidex'))
{
details.useVersion "2.0.0"
}
}
}
}
dependencies
{
implementation 'androidx.test:runner:1.1.0'
implementation 'androidx.test.espresso:espresso-core:3.1.0'
// androidTestImplementation 'com.android.support.test:runner:1.0.2'
// androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// lifecycle components
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.0.0'
implementation 'androidx.lifecycle:lifecycle-livedata-core:2.0.0'
kapt 'androidx.lifecycle:lifecycle-compiler:2.0.0'
// implementation 'android.arch.lifecycle:extensions:1.1.1'
// kapt "android.arch.lifecycle:compiler:1.1.1"
// room components
// implementation 'android.arch.persistence.room:runtime:1.1.1'
implementation 'androidx.room:room-runtime:2.0.0'
// data binding components
annotationProcessor "com.android.databinding:compiler:3.1.4"
implementation 'io.reactivex.rxjava2:rxjava:2.2.2'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation …Run Code Online (Sandbox Code Playgroud) 迁移到AndroidX后,由于迁移,我遇到了以下问题:
失败:构建失败,发生异常。
com.android.builder.dexing.DexArchiveMergerException:合并dex归档文件时出错:/home/lexy/AndroidStudioProjects/Testbucks/app/build/intermediates/transforms/dexBuilder/debug/0.jar、/home/lexy/AndroidStudioProjects/Testbucks/ app / build / intermediates / transforms / dexBuilder / debug / 1.jar,/ home / lexy / AndroidStudioProjects / Testbucks / app / build / intermediates / transforms / dexBuilder / debug / 2.jar,/ home / lexy / AndroidStudioProjects / Testbucks / app / build / intermediates / transforms / dexBuilder / debug / 3.jar,/ home / lexy / AndroidStudioProjects / Testbucks / app / build / intermediates / transforms / dexBuilder / debug / 4.jar,/ …
android gradle android-studio android-gradle-plugin androidx
尝试构建Android应用程序时遇到以下问题。我遇到了一些关于强制或使用手动依赖项解决策略的android帖子。这似乎无法解决问题。
有人问过类似的问题:类似的堆栈溢出问题。
还打开了一个问题:类似问题的“问题跟踪器”。
* What went wrong:
Execution failed for task ':app:lintVitalSunmiRelease'.
> Could not resolve all artifacts for configuration ':data:debugAndroidTestRuntimeClasspath'.
> Could not resolve androidx.arch.core:core-runtime:2.0.1-alpha01.
Required by:
project :data
> Cannot find a version of 'androidx.arch.core:core-runtime' that satisfies the version constraints:
Dependency path 'shopperapp:data:unspecified' --> 'androidx.room:room-testing:2.1.0-alpha06' --> 'androidx.arch.core:core-runtime:2.0.1'
Dependency path 'shopperapp:data:unspecified' --> 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha03' --> 'androidx.arch.core:core-runtime:2.0.1-alpha01'
Dependency path 'shopperapp:data:unspecified' --> 'androidx.room:room-rxjava2:2.0.0-rc01' --> 'androidx.arch.core:core-runtime:2.0.0-rc01'
Dependency path 'shopperapp:data:unspecified' --> 'androidx.room:room-runtime:2.1.0-alpha06' --> 'androidx.arch.core:core-runtime:2.0.1'
Dependency path 'shopperapp:data:unspecified' --> 'androidx.room:room-testing:2.1.0-alpha06' --> …Run Code Online (Sandbox Code Playgroud) 我想为测试 android 应用程序创建下面的视图。这些是我创建视图所遵循的当前步骤:
当我运行应用程序时,视图如下图所示:
我曾尝试使用底部导航视图,主浮动操作按钮被膨胀为菜单项中的操作布局。使用这种方法只允许显示菜单项及其测试,但不显示浮动操作按钮。
什么是最好的使用方法。使用BottomAppBar 或使用BottomNavigationView。我正在尝试查看是否可以使用可用的材料组件而无需执行 hack。
XML 文件如下:
活动主
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/bar"
app:srcCompat="@mipmap/sharp_local_atm_black_24" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:fabAlignmentMode="center"
app:fabCradleRoundedCornerRadius="0dp"
app:fabCradleMargin="0dp"
app:fabAnimationMode="slide"
app:labelVisibilityMode="labeled"
app:fabCradleVerticalOffset="8dp"
app:menu="@menu/app_bar_menu"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
菜单 XML:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/app_bar_home"
android:icon="@mipmap/sharp_home_black_24"
android:title="@string/home"
app:showAsAction="always"/>
<item
android:id="@+id/app_bar_wallet"
android:icon="@mipmap/sharp_account_balance_wallet_black_24"
android:title="@string/wallet"
app:showAsAction="always"/>
<item
android:id="@+id/app_bar_atm"
android:title="CASH"
app:showAsAction="always"/>
<item
android:id="@+id/app_bar_cart"
android:icon="@mipmap/sharp_shopping_cart_black_24"
android:title="@string/cart"
app:showAsAction="always"/>
<item
android:id="@+id/app_bar_more"
android:icon="@mipmap/sharp_menu_black_24"
android:title="@string/more"
app:showAsAction="always"/> …Run Code Online (Sandbox Code Playgroud)