3

나는 Travis CI를 사용하여 테스트를 거쳐 codecov에서 결과를 확인하려고합니다.Travis CI & CodeCov Android

가 .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 (응용 프로그램)이 :

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') 
} 

우리가 실행하려고하는 테스트 인 계측 된 시험. 트래비스 로그의 출력은 다음과 같습니다

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 

또한 단순히 두 숫자를 추가하고 결과를 확인하는 자동 생성 된 테스트가 있었다 그러나 트래비스조차 통과하지 않았다.

누구나이 혼란을 해결할 수 있습니까?

+0

HttpClient를 사용하고 있지 않지만 아마도 도움이되는 몇 가지 관련 답변 아래에 추가되었습니다. – albodelu

답변

0

this related questionHTTPClient-NoSuchMethodError for .releaseConnection을 읽으십시오.

HttpRequestBase#releaseConnection()가 definetely 4.2 version에 첨가하는 방법.

아마도 당신은 항아리가 있습니다. 컴파일러에 컴파일 오류가없는 경우 런타임에 다른 버전의 클래스를로드 할 수 있습니다. 실제 원인은 이며 빌드 도구에 따라 다릅니다. maven/gradle을 사용하는 경우 일부 전 이적 종속성이있을 수 있습니다.

실제로 HttpRequestBase#releaseConnection() 메서드는 AbstractExecutionAwareRequest#reset()에 대한 프록시 프록시를 그냥 프록시합니다. 그리고 AbstractExecutionAwareRequest#reset() 방금 ​​메서드 실행을 취소하십시오. 아마 그것이 필요한 것이 아닙니다.

httpClient 리소스를 실행하고 해제하는 올바른 방법은 입니다. httpResponse를 닫으면 httpClient의 internal threadPool에서 Thread를 해제 할 수 있습니다. quickstart 더 이상 (이되지 않습니다)를 사용 .releaseConnection() 것을 볼 수 있습니다, 대신 응답 개체를 닫을에서

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(); 
     } 
    } 

보장하기 위해 연결 이 닫혀 있습니다. 당신이 BasicHttpContext 이전/새로운 버전 jar 파일을 가지고있는 것처럼

것 같습니다 :

은 ( here에서) 다른 httpclient 또는 httpcore 버전을 사용해보십시오. 직접적인 충돌이있는 경우 ClassNotFoundException을 받게됩니다. ClassLoaders는 일반적으로이 종류에 대한 바보입니다.이 경우에는 클래스가 존재하지만, 다른 라이브러리 (Context를 호출하는 httpclient가 이라고 생각합니다)가 컴파일 된 메서드 인 이 없습니다. 당신은 또한 당신의 /app/build.gradle like thisthe removed apache library을 추가 할 수 있습니다 23 + API에 대한

:

android { 
compileSdkVersion 24 
buildToolsVersion "24.0.3" 
    useLibrary 'org.apache.http.legacy' 
    ... 
} 

안드로이드 6.0 릴리스는 Apache HTTP 클라이언트에 대한 지원을 제거합니다. 앱이이 클라이언트를 사용 중이며 Android 2.3 (API 레벨 9) 또는 이상을 타겟팅하는 경우 HttpURLConnection 클래스를 대신 사용하십시오. 이 API는

this articlethis sample 안드로이드와 트래비스-CI에 대한 Codecov을 구성하는 데 유용 것 ... 효율적 더 :

생성 계측 테스트 코드 커버리지 보고서 빌드에 작은 변화를 요구한다 스크립트.

android { 
    testOptions { 
    unitTests.all { 
     jacoco { 
     includeNoLocationClasses = true 
     } 
    } 
    } 
} 

다음으로, 우리는 보고서 출력을 구성해야합니다 커버리지 보고서에 의해 우리의 테스트를 무시 방지하기 위해

android { 
    buildTypes { 
    debug { 
     testCoverageEnabled true 
    } 
    } 
} 
, 우리는 다음과 같은 설정 구성해야합니다 :

jacocoAndroidUnitTestReport { 
    csv.enabled false 
    html.enabled true 
    xml.enabled true 
}