小编a_s*_*ber的帖子

安卓,摇篮。如何启动具体的仪表测试方法?

当我想开始特定的本地单元测试(在文件夹“test”中)时,我开始(Dev是 buildType):

  gradlew testDevUnitTest --tests com.example.StringUtilTest.testMethod
Run Code Online (Sandbox Code Playgroud)

好的。这是工作。

但我也想启动特定的仪器测试方法(在文件夹“androidTest”中)。

gradlew connectedDevAndroidTest --tests com.example.StringUtilTest.testSelectLanguageFragment
Run Code Online (Sandbox Code Playgroud)

但我得到错误:

> Unknown command-line option '--tests'.
Run Code Online (Sandbox Code Playgroud)

android-gradle-plugin

8
推荐指数
1
解决办法
1415
查看次数

在模块 jetified-hamcrest-core-1.3.jar 中发现重复的类 org.hamcrest.BaseDescription

安卓工作室3.6

应用程序/build.gradle:

 androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'com.azimolabs.conditionwatcher:conditionwatcher:0.2'
    // Espresso framework
    androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version"
    androidTestImplementation "androidx.test.espresso:espresso-intents:$espresso_version"
    androidTestImplementation "androidx.test.espresso:espresso-contrib:$espresso_version"
    androidTestImplementation 'org.hamcrest:hamcrest-junit:2.0.0.0'

    // UI Automator framework
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
    androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.8.0'

    // for test fragments
    debugImplementation 'androidx.fragment:fragment-testing:1.2.0-rc02'

    testImplementation 'junit:junit:4.12'
    testImplementation 'com.nhaarman:mockito-kotlin-kt1.1:1.5.0'
Run Code Online (Sandbox Code Playgroud)

在 gradle.properties 中:

android.useAndroidX=true
android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)

这是我的 Espresso 仪器测试:

import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.hamcrest.text.MatchesPattern
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class FeedbackActivityTransportTest {
 @Test
    fun buttonSend_click_checkRequest() {
        val request = mockServer.takeRequest();
        assertEquals("POST", request.method)
        assertThat(
            request.body.toString(),
            MatchesPattern.matchesPattern("(\"feedback.*\\\"type\\\":2\"))")
        )
    }
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

Duplicate class org.hamcrest.BaseDescription …
Run Code Online (Sandbox Code Playgroud)

android hamcrest android-espresso

8
推荐指数
2
解决办法
7805
查看次数

在不更改colorAccent的情况下无法更改MaterialButton上的背景颜色

Android Studio 3.2.1这是我的布局:

<com.google.android.material.button.MaterialButton
                android:id="@+id/bittrexJsonViewButton"
                android:layout_width="0dp"
                android:layout_height="@dimen/min_height"
                android:layout_marginStart="@dimen/half_default_margin"
                android:layout_marginEnd="@dimen/half_default_margin"
                android:text="@string/json_view"
                app:layout_constraintBottom_toBottomOf="@+id/binanceJsonViewButton"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@+id/binanceJsonViewButton"
                app:layout_constraintTop_toTopOf="@+id/binanceJsonViewButton" />
Run Code Online (Sandbox Code Playgroud)

更改MaterialButton的背景,我在styles.xml中更改colorAccent

<item name="colorAccent">@color/colorAccent</item>
Run Code Online (Sandbox Code Playgroud)

真好 是工作。

但是问题是:我不想更改colorAccent。我想为MaterialButtoncolorAccent使用不同的背景颜色

属性:

android:background="#aabbcc"
Run Code Online (Sandbox Code Playgroud)

没有帮助。

android android-button material-design material-components material-components-android

7
推荐指数
5
解决办法
1763
查看次数

无法从命令行启动Android模拟器

Windows 7,Android Studio 2.3

我有3个模拟器.所有成功都从Android Studio开始.

但我想从命令行启动它们.所以我的步骤(来自命令行):

  1. 模拟器-list-avds

成功展示了我所有的模拟器:

  1. Nexus_3_7_API_17_ver_4_2_1
  2. Nexus_3_7_hdpi_API_24_7_0
  3. Nexus_5_96_xxhdpi_API_24_7_0

所以我想开始其中一个:

模拟器-avd Nexus_3_7_API_17_ver_4_2_1

但我得到错误:

[8648]:ERROR:./android/qt/qt_setup.cpp:28:Qt library not found at ..\emulator\lib64\qt\lib
Could not launch '..\emulator/qemu/windows-x86_64/qemu-system-i386.exe': No such file or directory
Run Code Online (Sandbox Code Playgroud)

command-line android android-emulator

6
推荐指数
2
解决办法
6547
查看次数

添加本地外部 jar - 不应指向项目目录中的文件

在我的 Maven 项目中,我使用这样的自定义外部my-custom-externaljar:

pom.xml

<dependencies>
    <dependency>
        <groupId>com.myproject</groupId>
        <artifactId>my-custom-external</artifactId>
        <version>1.0-SNAPSHOT</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/libs/my-custom-external-1.0-SNAPSHOT.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib-jdk8</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我成功构建了我的项目,mvn verify但在控制台中我有警告:

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.myproject:prj_1:jar:1.0-SNAPSHOT
[WARNING] 'dependencies.dependency.systemPath' for com.myproject:my-custom-extneral:jar should not point at files within the project directory, ${project.basedir}/libs/my-custom-extneral-1.0-SNAPSHOT.jar will be unresolvable by dependent projects @ line 62, column 25
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability …
Run Code Online (Sandbox Code Playgroud)

maven

6
推荐指数
3
解决办法
2万
查看次数

为什么扩展功能在另一个模块中不可见?

我的Android项目有两个模块:

app
common
Run Code Online (Sandbox Code Playgroud)

settings.gradle中:

rootProject.name='My project'
include ':app'
include ':common'
Run Code Online (Sandbox Code Playgroud)

在我的 build.gradle 中:

implementation project(':common')
Run Code Online (Sandbox Code Playgroud)

在公共包中,我有StringUtil.kt和下一个扩展函数:

fun String.isEmailValid(): Boolean {
    return !TextUtils.isEmpty(this) && android.util.Patterns.EMAIL_ADDRESS.matcher(this).matches()
}
Run Code Online (Sandbox Code Playgroud)

这个类中我可以使用这样的扩展函数:

val str = ""
str.isEmailValid()
Run Code Online (Sandbox Code Playgroud)

但在app模块中我有课

class RegistrationViewModel(application: Application) : AndroidViewModel(application) {

  fun doClickRegistration(email: String?, password: String?, retypePassword: String?) {
        val str = ""
        str.isEmailValid()
    }
}
Run Code Online (Sandbox Code Playgroud)

但现在我得到编译错误:

未解决的参考:isEmailValid

android kotlin kotlin-extension

6
推荐指数
1
解决办法
3527
查看次数

未设置特定文件夹和所有子文件夹的 Java 版本

Linux Mint 20
Java 8、11。SDKMAN
:5.12.14

当前 Java 版本 = 11

我有一个MyProject包含 45 个子文件夹的文件夹:

MyProject
- mySubfolder1
- mySubfolder2
-...
- mySubfolder45
Run Code Online (Sandbox Code Playgroud)

MyProject我想将文件夹及其所有 45 个子文件夹的特定 Java 版本设置为 8 。

.sdkmanrc我在文件夹中创建文件,MyProject内容如下:

# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=jdk1.8.0_202
Run Code Online (Sandbox Code Playgroud)

当我打开文件夹MyProject并使用此命令时:

java -version
Run Code Online (Sandbox Code Playgroud)

我有java = 1.8

好的。效果很好。

但是,当我打开任何子文件夹时,例如mySubfolder2,Java版本是11。

MyProject是否可以为文件夹及其所有子文件夹设置 Java 8 ?

我不想.sdkmanrc在所有子文件夹中创建文件

java sdkman

6
推荐指数
1
解决办法
774
查看次数

Emacs,hl 线背景。如何设置背景颜色为透明?

Windows 7、Emacs 25.1

如果我想更改hl-line的背景颜色,我会这样做:

(set-face-background 'hl-line "#333333")
Run Code Online (Sandbox Code Playgroud)

好的。但是我如何为hl 线背景色设置透明(例如 50%)?

emacs

5
推荐指数
1
解决办法
1444
查看次数

Emacs:是否可以折叠(折叠/展开)json 对象/集合?

Windows 10(64 位)、Emacs 25.1。

假设我有一个大的 json 文件。如果我可以折叠(折叠/展开)这个 json 的任何节点,那就非常舒服了。我用 Notepad++ 来做这个。

这里的例子:

在此输入图像描述

在此输入图像描述

在 Emacs 中可以做同样的事情吗?谢谢。

emacs json folding

5
推荐指数
0
解决办法
2150
查看次数

Android:Espresso:WireMock java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/io/Resources;

安卓工作室 3.2。我想在我的 Espresso 测试中使用WireMock

在 build.gradle

buildscript {
    ext.KOTLIN_VERSION = '1.3.21'
    ext.ESPRESSO_VERSION = '3.2.0-alpha02'

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
Run Code Online (Sandbox Code Playgroud)

在 app/build.gradle 中

android {
    dataBinding {
        enabled = true
    }
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myproject"
        minSdkVersion 18
        targetSdkVersion 28
        versionCode 6
        versionName "0.0.7"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    sourceSets {
        main.java.srcDirs += …
Run Code Online (Sandbox Code Playgroud)

android android-espresso wiremock

5
推荐指数
1
解决办法
541
查看次数