- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 Travis CI 并让它运行通过测试以在 codecov 上查看结果。
.travis.yml:
language: android
sudo: required
jdk: oraclejdk8
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
env:
global:
- ANDROID_API=25
- EMULATOR_API=21
- ANDROID_BUILD_TOOLS=25.0.0
- ADB_INSTALL_TIMEOUT=5 # minutes
android:
components:
- tools
- platform-tools
- build-tools-$ANDROID_BUILD_TOOLS
- android-$ANDROID_API
- android-$EMULATOR_API_LEVEL
- extra-google-m2repository
- extra-android-m2repository # for design library
- addon-google_apis-google-19 # google play services
- sys-img-armeabi-v7a-addon-google_apis-google-$ANDROID_API_LEVEL
- sys-img-armeabi-v7a-addon-google_apis-google-$EMULATOR_API_LEVEL
licenses:
- android-sdk-preview-license-.+
- android-sdk-license-.+
- google-gdk-license-.+
before_install:
- mkdir "$ANDROID_HOME/licenses" || true
- echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
- echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
- chmod +x gradlew
#- ./gradlew dependencies || true # DON'T ADD unless you are getting "Install missing components using SDK manager"
#Source: https://medium.com/@oldergod/constraint-layout-and-circleci-travis-d50342696d2
script:
- ./gradlew build jacocoTestReport assembleAndroidTest
- echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell setprop dalvik.vm.dexopt-flags v=n,o=v
- ./gradlew connectedCheck
after_success:
- bash <(curl -s https://codecov.io/bash)
build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(app):
apply plugin: 'com.android.application'
apply plugin: 'jacoco-android'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "<ID>"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
testOptions {
unitTests.returnDefaultValues = true
}
lintOptions {
abortOnError false
}
productFlavors {
free {}
paid {}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile files('libs/httpclient-4.5.1.jar')
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-vector-drawable:24.2.1'
testCompile 'junit:junit:4.12'
compile files('libs/themoviedbapi-4.3.jar')
compile files('libs/api-common-2.0.jar')
compile files('libs/commons-codec-1.9.jar')
compile files('libs/commons-lang3-3.4.jar')
compile files('libs/httpcore-4.4.3.jar')
compile files('libs/jackson-annotations-2.7.1.jar')
compile files('libs/jackson-core-2.7.1.jar')
compile files('libs/jackson-databind-2.7.1.jar')
compile files('libs/slf4j-api-1.7.16.jar')
}
我们尝试运行的测试是一个插桩测试。 Travis 日志的输出如下所示:
com.example.fabian.tinf15b4_lsmf.SeeMovieDetailsTest > seeMovieDetails[test(AVD) - 5.0.2] [31mFAILED [0m
java.lang.NoSuchMethodError: No virtual method releaseConnection()V in class Lorg/apache/http/client/methods/HttpRequestBase; or its super classes (declaration of 'org.apache.http.client.methods.HttpRequestBase' appears in /system/framework/ext.jar)
at org.yamj.api.common.http.DigestedResponseReader.processRequest(DigestedResponseReader.java:119)
Tests on test(AVD) - 5.0.2 failed: Instrumentation run failed due to 'java.lang.NoSuchMethodError'
:app:connectedFreeDebugAndroidTest FAILED
还有自动生成的测试,它只是将两个数字相加并检查结果,但 Travis 甚至没有检查它。
谁能帮忙解决这个问题?
最佳答案
阅读this related question关于HTTPClient - .releaseConnection 的 NoSuchMethodError
。
The method
HttpRequestBase#releaseConnection()
definetely was added at 4.2 version.Probably you have jar hell. If the compiler has no compilation errors another version of the class can be loaded at runtime. The real cause depends on your build tool. If you are using maven/gradle, there can be some transitive dependency.
So actually
HttpRequestBase#releaseConnection()
method just proxy invocation toAbstractExecutionAwareRequest#reset()
. AndAbstractExecutionAwareRequest#reset()
just cancel method execution. Probably it is not what do you need.The correct way to execute and release httpClient resources is to close httpResponse, which means you can release Thread in httpClient's internal threadPool.
private static String makeRequest(HttpUriRequest httpRequest) throws IOException {
CloseableHttpResponse httpResponse = httpClient.execute(httpRequest);
try {
HttpEntity httpEntity = httpResponse.getEntity();
StringWriter writer = new StringWriter();
IOUtils.copy(httpEntity.getContent(), writer, "UTF-8");
return writer.toString();
} finally {
httpResponse.close();
}
}
In the quickstart you'll see that
.releaseConnection()
is no longer used (it is deprecated), instead the response object is closed to ensure connections are closed.
尝试不同的 httpclient
或 httpcore
版本(来自 here ):
It looks like you have a jar file with an old/newer version of BasicHttpContext. If there were a direct conflict, you'd receive a ClassNotFoundException. ClassLoaders are typically jerks about this kind of thing. In this case, the class exists, however, does not have the method that another library (I believe it's httpclient that's invoking the Context) was compiled against.
对于 API 23+,您还可以添加 the removed apache library在你的/app/build.gradle like this :
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
useLibrary 'org.apache.http.legacy'
...
}
Android 6.0 release removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the HttpURLConnection class instead. This API is more efficient...
this article和 this sample为 Android 和 Travis-ci 配置 Codecov 似乎很有用:
Generating instrumentation tests code coverage reports requires a minor change to the build script.
android {
buildTypes {
debug {
testCoverageEnabled true
}
}
}
To avoid ignoring our tests by the coverage report, we need to configure the following settings:
android {
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
}
Next, we need to configure report output:
jacocoAndroidUnitTestReport {
csv.enabled false
html.enabled true
xml.enabled true
}
关于android - Travis CI 和 CodeCov Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43941946/
我收到了这样的警告日志,我的构建失败了。 WARNING: We were unable to find a .travis.yml file. This may not be what you wa
我真的很想使用 Travis 而无需将 .travis.yml 存储在我的存储库的根文件夹中。知道它是否可以移动到不同的文件夹中、存储在另一个存储库中或在 Travis 网站上指定吗? 最佳答案 来自
我有 .travis.yml 文件在我的 repo 的根目录中,但 Travis-Ci 不断给我消息: Could not find .travis.yml, using standard confi
每当我推送一个新的提交时,Travis CI 都会使我的构建失败,并在每个日志的顶部显示这条消息: WARNING: We were unable to find a .travis.yml file
我正在尝试登录自己托管的 Travis Enterprise,但通常是 travis login和 travis login --pro正在尝试登录到通常的 Travis SAAS 环境 最佳答案 鉴
我希望在我的 Travis CI 存储库设置中声明环境变量,并在我的 .travis.yml 文件中使用它们来部署应用程序并在 Slack 中发布构建通知。 我在 Travis CI 存储库设置中设置
使用 .travis.yml 时,是否有一个环境变量包含 Travis-CI 中当前构建目录的名称?查看文档 here我没有看到。 最佳答案 您可能需要 $TRAVIS_BUILD_DIR,这是我们在
作为我定制的 travis 构建的一部分,我想使用 Travis command-line client在 after_success 脚本中。在这个特定的 repo 中每次成功构建之后,我需要它来触
我有以下 .travis.yml : sudo: required language: node_js branches: only: - master before_install:
我的本地存储库中有一个有效的 .travis.yml。让我们以 travis 帮助中的示例为例:https://github.com/travis-ci/build-stages-demo/blo
所以,我在 GitHub 上设置为另一个用户拥有的项目的合作者 (我有完全推送权等)。我可以设置 Travis 吗 这个项目?我在“存储库”列表中找不到存储库 特拉维斯。 最佳答案 只有存储库管理员可
每次推送到存储库 Y 时,有没有办法触发存储库 X 的 Travis CI 构建?具体来说,我希望每次推送到 http://github.com/tensorflow/tensorflow 时都开始构
我想针对许多浏览器测试我的 .js 框架的不同版本 我希望写一些类似的东西: language: node_js node_js: - 0.11 env: matrix: - BUILD=
我有一个在 Linux 和 OSX 上运行的 travis 作业,我希望能够使用它为每个平台部署不同的构建工件到 github 版本。我的 .travis.yml文件目前看起来像这样: languag
我在 Travis 文件中有以下部署脚本并面临多行命令问题。我尝试了很多组合,但找不到合适的解决方案。如果我将它提取到文件并从脚本属性调用它,它可以正常工作,但我们的目标是将所有命令作为多行命令放在脚
我在 Travis 文件中有以下部署脚本并面临多行命令问题。我尝试了很多组合,但找不到合适的解决方案。如果我将它提取到文件并从脚本属性调用它,它可以正常工作,但我们的目标是将所有命令作为多行命令放在脚
我正在尝试使用以下配置让 Travis 上传到 PyPI deploy: provider: pypi user: P403n1x87 password: $PYPI_PASSWORD
这是有问题的公共(public)存储库:https://travis-ci.org/agerwick/raw-sinatra-boilerplate 我按照此处的建议集成了 codeclimate 的
在那里,在我的项目中使用travis-ci时遇到了“分段错误”错误:IPython-Dashboard msg没有错误,并且在本地运行良好,我感到有些困惑。任何人都可以提出解决问题的任何想法,谢谢。
我有一个带有子目录 ( test ) 的 gem,其中包含用于测试项目的 Rails 3.1.1 应用程序。我正在尝试设置 Travis-CI 以进行持续集成,但是我不知道如何设置我的 .travis
我是一名优秀的程序员,十分优秀!