2012-11-27 4 views
2

이클립스로 만든 하나의 액티비티를 가진 샘플 Android 앱이 있습니다. 나는이 프로젝트에 대한 개미 빌드 파일 구축이 명령을 실행 :개미로 안드로이드 테스트 프로젝트를 만들 수 없습니다.

android create project --target 8 --name SampleApp --path ./SampleApp --activity MainActivity --package com.example.sampleapp 

"개미 디버그"프로젝트를 성공적으로 구축 실행을하고 APK 파일 생성 : 이제

-post-build: 

debug: 

BUILD SUCCESSFUL 
Total time: 1 second 

, 내가 만들려면 안드로이드 테스트 프로젝트. 이 명령을 실행합니다 :

이렇게하면 빌드 파일이 포함 된 SampleAppTest 디렉토리가 성공적으로 만들어졌습니다. 하나의 클래스 src/com/example/sampleapp/MainActivityTest.java가 있습니다.

package com.example.sampleapp; 

import android.test.ActivityInstrumentationTestCase2; 

public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> { 

    public MainActivityTest() { 
     super("com.example.sampleapp", MainActivity.class); 
    } 

} 

이 프로젝트를 빌드하고 싶습니다. 이 튜토리얼에서는 여기에 http://developer.android.com/tools/testing/testing_otheride.html#RunTestsAnt이 있는데, "ant run-tests"를 할 수 있어야한다고 나와 있습니다. 불행하게도이 대상이 존재하지 않습니다

$ ant run-tests 
Buildfile: /Users/cmuraru/Work/androidtest/SampleAppTest/build.xml 

BUILD FAILED 
Target "run-tests" does not exist in the project "SampleAppTest". 

Total time: 0 seconds 

을 나는 시도 (여기서 SampleApp에서)를 MainActivity 클래스를 찾을 수 없다는, 컴파일 할 때 "개미 디버그"나는 오류가 발생합니다. "개미 테스트"를 시도 할 때

-compile: 
    [javac] Compiling 2 source files to /Users/cmuraru/Work/androidtest/build/test/classes 
    [javac] /Users/cmuraru/Work/androidtest/SampleAppTest/src/com/example/sampleapp/MainActivityTest.java:15: cannot find symbol 
    [javac] symbol: class MainActivity 
    [javac] public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> { 
    [javac]                  ^
    [javac] /Users/cmuraru/Work/androidtest/SampleAppTest/src/com/example/sampleapp/MainActivityTest.java:18: cannot find symbol 
    [javac] symbol : class MainActivity 
    [javac] location: class com.example.sampleapp.MainActivityTest 
    [javac]   super("com.example.sampleapp", MainActivity.class); 
    [javac]          ^
    [javac] 2 errors 

BUILD FAILED 
/Users/cmuraru/Work/android-sdk-macosx/tools/ant/build.xml:705: The following error occurred while executing this line: 
/Users/cmuraru/Work/android-sdk-macosx/tools/ant/build.xml:718: Compile failed; see the compiler error output for details. 

Total time: 1 second 

, 또한 실패

내가 놓친 게 무엇
test: 
    [echo] Running tests ... 
    [exec] INSTRUMENTATION_STATUS: id=ActivityManagerService 
    [exec] INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.example.sampleapp.tests/android.test.InstrumentationTestRunner} 
    [exec] INSTRUMENTATION_STATUS_CODE: -1 
    [exec] android.util.AndroidException: INSTRUMENTATION_FAILED: com.example.sampleapp.tests/android.test.InstrumentationTestRunner 
    [exec]  at com.android.commands.am.Am.runInstrument(Am.java:616) 
    [exec]  at com.android.commands.am.Am.run(Am.java:118) 
    [exec]  at com.android.commands.am.Am.main(Am.java:81) 
    [exec]  at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method) 
    [exec]  at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:237) 
    [exec]  at dalvik.system.NativeStart.main(Native Method) 

은/잘못 여기서 뭐? 어떤 도움도 기꺼이 감사드립니다.

답변

2

좋아요, 문제를 발견했습니다. ant.properties에서 out.dir 위치를 "../build"로 변경했음을 언급하지 못했습니다. 이 때문에 컴파일러는 SampleAppTest를 빌드 할 때 SampleApp의 클래스 파일을 가져올 위치를 알지 못합니다. 그래서 한 가지 해결책은 ant.properties에서 out.dir 항목을 삭제하는 것이지만, 나는 그것을 원하지 않았다. 나는 컴파일러에게이 클래스들을 어디에서 가져올지를 알려줄 수있는 방법을 찾아야했다. 내가 찾은 솔루션은과 같이 build.xml 파일에서 "-compile"대상을 무시하는 것이었다 대신 수동으로 업데이트 ant.properties의

<property name="SampleApp.build.location" value="../build"/> 
    <target name="-compile" depends="-build-setup, -pre-build, -code-gen, -pre-compile"> 
     <do-only-if-manifest-hasCode elseText="hasCode = false. Skipping..."> 
      <!-- merge the project's own classpath and the tested project's classpath --> 
      <path id="project.javac.classpath"> 
       <path refid="project.all.jars.path" /> 
       <path refid="tested.project.classpath" /> 
      </path> 
      <javac encoding="${java.encoding}" 
        source="${java.source}" target="${java.target}" 
        debug="true" extdirs="" includeantruntime="false" 
        destdir="${out.classes.absolute.dir}" 
        bootclasspathref="project.target.class.path" 
        verbose="${verbose}" 
        classpathref="project.javac.classpath" 
        fork="${need.javac.fork}"> 
       <src path="${source.absolute.dir}" /> 
       <src path="${gen.absolute.dir}" /> 
       <compilerarg line="${java.compilerargs}" /> 
       <classpath> 
        <!-- steff: we changed one line here !--> 
        <fileset dir="${SampleApp.build.location}/classes" includes="*"/> 
       </classpath> 
      </javac> 

      <!-- if the project is instrumented, intrument the classes --> 
      <if condition="${build.is.instrumented}"> 
       <then> 
        <echo level="info">Instrumenting classes from ${out.absolute.dir}/classes...</echo> 

        <!-- build the filter to remove R, Manifest, BuildConfig --> 
        <getemmafilter 
          appPackage="${project.app.package}" 
          libraryPackagesRefId="project.library.packages" 
          filterOut="emma.default.filter"/> 

        <!-- define where the .em file is going. This may have been 
         setup already if this is a library --> 
        <property name="emma.coverage.absolute.file" location="${out.absolute.dir}/coverage.em" /> 

        <!-- It only instruments class files, not any external libs --> 
        <emma enabled="true"> 
         <instr verbosity="${verbosity}" 
           mode="overwrite" 
           instrpath="${out.absolute.dir}/classes" 
           outdir="${out.absolute.dir}/classes" 
           metadatafile="${emma.coverage.absolute.file}"> 
          <filter excludes="${emma.default.filter}" /> 
          <filter value="${emma.filter}" /> 
         </instr> 
        </emma> 
       </then> 
      </if> 

      <!-- if the project is a library then we generate a jar file --> 
      <if condition="${project.is.library}"> 
       <then> 
        <echo level="info">Creating library output jar file...</echo> 
        <property name="out.library.jar.file" location="${out.absolute.dir}/classes.jar" /> 
        <if> 
         <condition> 
          <length string="${android.package.excludes}" trim="true" when="greater" length="0" /> 
         </condition> 
         <then> 
          <echo level="info">Custom jar packaging exclusion: ${android.package.excludes}</echo> 
         </then> 
        </if> 

        <propertybyreplace name="project.app.package.path" input="${project.app.package}" replace="." with="/" /> 

        <jar destfile="${out.library.jar.file}"> 
         <fileset dir="${out.classes.absolute.dir}" 
           includes="**/*.class" 
           excludes="${project.app.package.path}/R.class ${project.app.package.path}/R$*.class ${project.app.package.path}/BuildConfig.class"/> 
         <fileset dir="${source.absolute.dir}" excludes="**/*.java ${android.package.excludes}" /> 
        </jar> 
       </then> 
      </if> 

     </do-only-if-manifest-hasCode> 
    </target> 
+0

답을 표시하십시오. – shkschneider

+0

이렇게하려면 2 일을 기다려야합니다. –

0

을 할 수있는 방법이있다. 다음 명령을 실행하여 명령 줄에서 :

android update test-project -m <project path> -p <test project path> 

이 명령을 실행 한 후, 테스트 프로젝트에서 직접 개미 디버그를 실행할 수 있습니다. 참고 : JUnit 관련 오류가있는 경우 테스트 프로젝트 libs 폴더에 Junit jar 파일을 추가하십시오.

관련 문제