0

나는 앱을 가지고 있고 그것을위한 단위 테스트 케이스를 작성 중이다.
내 테스트 케이스는 큰 경고의 목록과 1 오류
이어 다음 링크 및 하위 페이지 Building Instrumented Unit TestsInstrumented Android Unit Test and ProGuard

오류 및 일부 경고 내가 디버그에서 난독 화를 제거하면, 내가 할

Warning:there were 10 unresolved references to classes or interfaces. You may need to add missing library jars or update their versions. If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options. (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass) Warning:there were 5 instances of library classes depending on program classes. You must avoid such dependencies, since the program classes will be processed, while the library classes will remain unchanged. (http://proguard.sourceforge.net/manual/troubleshooting.html#dependency) Warning:there were 3 unresolved references to program class members. Your input classes appear to be inconsistent. You may need to recompile the code. (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember) Warning:Exception while processing task java.io.IOException: Please correct the above warnings first. :app:transformClassesAndResourcesWithProguardForDebugAndroidTest FAILED

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForDebugAndroidTest'. java.io.IOException: Please correct the above warnings first.

을 제공합니다 64K 오류!

Error:The number of method references in a .dex file cannot exceed 64K. Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

내가 뭘 잘못하고 있니?

응용 프로그램 build.gradle

android { 
compileSdkVersion 24 
buildToolsVersion "23.0.3" 

defaultConfig { 
    applicationId "com.tyagiabhinav.xyz" 
    minSdkVersion 16 
    targetSdkVersion 24 
    versionCode 1 
    versionName "1.0" 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
} 
buildTypes { 
    debug { 
     minifyEnabled true 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
    release { 
     minifyEnabled true 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
    } 
} 
dependencies 
{ 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:24.2.0' 
    compile 'com.android.support:design:24.2.0' 
    compile 'com.android.support:support-annotations:24.2.0' 
    ...... 
    androidTestCompile 'com.android.support:support-annotations:24.2.0' 
    androidTestCompile 'com.android.support.test:runner:0.5' 
    androidTestCompile 'com.android.support.test:rules:0.5' 
} 

테스트 자바 클래스

package com.tyagiabhinav.xyz; 

import android.content.Context; 
import android.support.test.InstrumentationRegistry; 
import android.support.test.runner.AndroidJUnit4; 

import com.tyagiabhinav.xyz.Util.PrefHelper; 

import org.junit.Assert; 
import org.junit.Before; 
import org.junit.Test; 
import org.junit.runner.RunWith; 

/** 
* Created by abhinavtyagi on 24/08/16. 
*/ 


@RunWith(AndroidJUnit4.class) 
public class PrefTester { 

    Context mMockContext; 

    private PrefTester() { 
     super(); 
    } 

    @Before 
    public void setUp() { 
     mMockContext = InstrumentationRegistry.getTargetContext(); 
     PrefHelper.init(mMockContext); 
    } 

    @Test 
    public void testSharedPref(){ 
     Assert.assertEquals(false,PrefHelper.isLoggedIn()); 
    } 

} 

답변

0

당신은 디버그 빌드 난독 화를 실행하고 있습니다. Proguard는 Java 코드에서 클래스를 제거 할 수 있습니다. build.gradle 파일에서 "minifyEnabled false"를 설정하여 프로 가드 끄기

buildTypes { 
    debug { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
+0

프로 가드를 제거하면 64k 오류가 발생합니다. 내 코드는 큰 코드가 아닙니다. 작은 응용 프로그램입니다. 하지만 어떻게 든이 테스트 케이스를 작성한 후에는 컴파일하는 동안 64K 오류가 발생합니다. –

0

변경 사항이 거의없고 문제가 해결되었습니다!


가 (응용 프로그램) 디버그

설정 난독 거짓 시작 화면을

@RunWith(AndroidJUnit4.class) 
public class PrefTester { 

    Context mMockContext; 

    @Rule 
    public ActivityTestRule<SplashActivity> mActivityRule = new ActivityTestRule<>(SplashActivity.class); 

    @Before 
    public void setUp() { 
     mMockContext = mActivityRule.getActivity().getApplicationContext(); 
     PrefHelper.init(mMockContext); 
    } 

    @Test 
    public void testSharedPref(){ 
     Assert.assertEquals(false,PrefHelper.isLoggedIn()); 
    } 

} 

build.gradle를 열어 컨텍스트를 얻을 수있는 방법을 변경 테스트 코드 ->minifyEnabled false
활성화 multidex ->multiDexEnabled true
종속성 ->compile 'com.android.support:multidex:1.0.1'

이 질문을 게시하기 전에 build.gradle 접근 방식을 테스트했는데 잘못된 방식으로 컨텍스트를 가져 오는 것 같습니다. 위의 변경 사항의 조합이 현재 저에게 효과적입니다.

0

proguard-rules.pro 파일에 무엇이 있습니까? 그것을 제거하고 간단하게 기본 안드로이드 규칙을 사용해 볼 수 있습니다.

참고로, 귀하의 의존성을 재평가하고 싶을 것 같습니다. 당신이 보여준 당신의 gradle 파일의 스 니펫 (snippet)에서, 당신이 그 의존성들로 64K dex 제한을 치는 것 같지는 않습니다. 위에 열거하지 않은 도서관을 더 포함하고 있습니까? 프로젝트의 jar 파일에 라이브러리가 있습니까? (메서드의 수를 쉽게 설명 할 수 있습니다)

Multidex는 일종의 해킹입니다. 선택의 여지가 없다면 실제로 사용하면 안됩니다. 성능에 영향을 미치기 때문에/etc를 사용할 수 있으며 예기치 않게 갑자기 나타날 수있는 몇 가지 이상한 문제가 dex 파일에 있습니다. 예를 들어 - 매니페스트에서 참조한 모든 클래스는 기본 dex 파일에서 끝나야합니다. 이로 인해 별난 제약이 발생할 수 있습니다.

+0

해결되었습니다 ... 코드를 여러 번 청소 한 다음 다시 작성하십시오. –

+0

확실히 기쁘게 고쳐졌습니다! :-)하지만 multidex가 제공 한 정보에서이 문제를 해결할 수있는 적절한 방법이 아닌 것 같습니다. – tmtrademark