小编Acc*_*est的帖子

如何在Android Studio中为消息“调用要求API级别21(当前最小值为16)”启用lint错误?

我有一个方法setImageTintList()要求min API为21。但是,如果将gradle的min API设置为16,则该应用程序仍会生成而不会发出任何警告。

尽管有一条红线说:

setImageTintList()-调用需要API级别21(当前最小值为16)

它不显示任何警告,错误或编译错误。

我如何在android studio中设置皮棉警告级别,这样它会出错并可能在这种情况下阻止构建?

android android-lint android-studio android-gradle-plugin

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

如何使用包含重定向的 mockwebserver 测试服务调用?

我正在使用 mockwebserver 来模拟我的 android 应用程序的请求和响应。我正在测试通过一系列 4 次服务调用的登录功能。

  1. 获取访问令牌
  2. 重定向
  3. 获取用户信息(不同的基本网址)
  4. 获取一些其他东西(原始基本网址)

我正在尝试模拟重定向调用的响应。这是我的代码:

@Test
public void testSuccessfulLogin() throws Exception {
    // Post
    server.enqueue(new MockResponse()
            .setResponseCode(HTTP_OK)
            .setBody(getStringFromFile(getInstrumentation().getContext(), "access_token.json")));

    // Redirect
    server.enqueue(new MockResponse().setResponseCode(HTTP_MOVED_TEMP));

    // GET user info
    server.enqueue(new MockResponse().setResponseCode(HTTP_OK).setBody(getStringFromFile(getInstrumentation().getContext(), "userinfo.json")));

    // GET some other stuff
    server.enqueue(new MockResponse().setResponseCode(HTTP_OK)
            .setBody(getStringFromFile(getInstrumentation().getContext(), "sts.json")));

    // Init call
    loginWithoutWaiting(Data.serviceLoginUsername, Data.serviceLoginPassword);

    // Debug (need to loop 4 times to get all 4 call paths)
    RecordedRequest request = server.takeRequest();
    request.getPath();
}
Run Code Online (Sandbox Code Playgroud)

我的测试在重定向代码处失败。我不能登入。我在这里找到了一些提示但我不完全了解发生了什么,因此目前无法使其工作。

android robolectric android-testing mockwebserver okhttp3

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