在Syncing Gradle时突然,我收到此错误:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
android {
compileSdkVersion 28
buildToolsVersion "28.0.2"
defaultConfig {
applicationId "..."
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "..."
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
versionNameSuffix = version_suffix
[...]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
[...]
}
debug {
[...]
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.61"
implementation 'androidx.appcompat:appcompat:1.0.0-rc02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "com.android.support:preference-v7:28.0.0"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4' …Run Code Online (Sandbox Code Playgroud) android compilation android-studio android-gradle-plugin google-fabric
我刚刚更新到 Android Studio 4.1 Canary 9,但出现以下错误:
Missing essential plugin:
org.jetbrains.android
Please reinstall Android Studio from scratch.
Run Code Online (Sandbox Code Playgroud)
正如错误所说,我尝试从头开始重新安装 Android Studio,但没有任何变化。
我上周更新到了 Kotlin 1.5,在昨天看到 Google 打算让 Jetpack Compose 成为设计 UI 的首选选项之后,我想做一些测试。
问题是将我的项目更新到 Kotlin 1.5,在尝试构建项目时出现以下错误:
This version (1.0.0-beta07) of the Compose Compiler requires Kotlin version 1.4.32 but you appear to be using Kotlin version 1.5.0 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
Run Code Online (Sandbox Code Playgroud)
Kotlin 1.5 是否与 Jetpack Compose 不兼容?在谷歌搜索问题后,我找到了1.5.0-M2提到 Jetpack Compose 的版本,但不是以“不兼容”的方式。
你有什么答案吗?我应该使用suppressKotlinVersionCompatibilityCheck吗?在这种情况下,我可以将它直接添加到android.kotlinOptions模块的build.gradle文件中吗?
提前致谢。
编辑 1: 我发现我应该添加suppressKotlinVersionCompatibilityCheck为构建器参数:
android { …Run Code Online (Sandbox Code Playgroud) 经过一段令人尴尬的时间后,我刚刚发现新推荐的接收器 inonCharacteristicRead如BluetoothGattCallbackAndroid开发人员参考中所示:
public void onCharacteristicRead (BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,
byte[] value,
int status)
Run Code Online (Sandbox Code Playgroud)
readCharacteristic当我调用该服务时没有收到任何数据。然而,已弃用的(Google Developers)实际上确实收到了回调。
我一直在遵循官方指南中的所有步骤,但尝试实现新方法,这是迄今为止唯一在“新回调”中不起作用的方法。
有想法该怎么解决这个吗?我将使用已弃用的方法,但这不是我所热衷的。提前致谢。
任何人都可以提供有关如何在公开可用的 Android Q 上保存文件的准确教程,因为getExternalFilesDir()无法在 Android Q+ 中使用。
我已经处理这个问题好几天了,找不到任何解决方案。
我正在尝试下载一些 css、js 和 HTML 文件,以便将它们加载到 Webview 上。
现在,我有以下代码,用 Kotlin 编写:
companion object {
private const val TAG = "MainActivity"
private var rootDir: Path? = null
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
...
rootDir = getExternalFilesDir(null)
Log.v(TAG, "RootDir: ${rootDir!!.path}")
val cacheDir = File(rootDir!!, "cache")
if(!cacheDir.exists()) {
Log.v(TAG, "Creating cache dir (${cacheDir.path})")
try {
if (cacheDir.mkdirs())
Log.v(TAG, "Created cache dir correctly")
else
Log.v(TAG, "Could not create cache dir")
}catch (ex: …Run Code Online (Sandbox Code Playgroud) 我正在使用 Jetpack Compose 来渲染我的应用程序的 UI。我目前正在为库开发一些测试,但我无法找到任何正确的方法来检查权限。我目前正在使用伴奏者权限库来检查权限。然而,似乎在测试开始时已经授予了权限,即使我当前正在检查位置权限,据我所知,实际上不应该授予该权限。
我应该如何检查权限是否被授予,以及如何在权限对话框上执行点击?也许有这样的东西?
composeTestRule.onNodeWithText("While using the app").performClick()
Run Code Online (Sandbox Code Playgroud)
对我来说似乎很脏。
注意:我正在初始化,composeTestRule就像官方指南所示:
@get:Rule
val composeTestRule = createComposeRule()
Run Code Online (Sandbox Code Playgroud)
预先感谢您的帮助,如果需要,我很乐意提供更多信息。
编辑 1:记住将权限添加到清单中非常重要。就我而言,我在应用程序中为该库使用单独的模块,因此我忘记添加我请求的权限。例子:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.yourpackage"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>
Run Code Online (Sandbox Code Playgroud)
编辑2:指令,例如
composeTestRule.onNodeWithText("Precise").performClick()
composeTestRule.onNodeWithText("While using the app").performClick()
Run Code Online (Sandbox Code Playgroud)
完全不起作用,因为对话框位于撰写视图之外。也许使用原始浓缩咖啡?
最后的想法:经过一番深入的调查,似乎这可能无法通过 Jetpack Compose 测试进行测试,Espresso 也无法进行测试。这种测试必须使用UiAutomator(官方文档)来执行。
android automated-tests kotlin android-jetpack android-jetpack-compose
当更新到 Kotlin 1.7.0 时,由于最新版本的 Jetpack Compose 需要它,我发现 Room 不再工作。我使用kapt作为我的注释处理器,编译器抛出错误消息,例如:
[*] error: Query method parameters should either be a type that can be converted into a database column or a List / Array that contains such type. You can consider adding a Type Adapter for this.
Run Code Online (Sandbox Code Playgroud) 我正在用 pygame 用 Python 编写一个游戏,我想制作一个函数,从一个点沿特定方向绘制一条线,具有特定长度,例如,函数的定义是: def draw_line(position1: (int, int), angle: int, line_length: int, line_width: float, color: Color):
我可以做什么来计算绘制线条的第二个点?
我有一个问题的小示意图,我想得到position2,用pygame画线。
android ×6
kotlin ×3
android-room ×1
angle ×1
bluetooth ×1
compilation ×1
file ×1
kapt ×1
line ×1
permissions ×1
position ×1
pygame ×1
python ×1