1
回答
菜鸟提问:linux 下面使用ant构建apk失败
华为云数据库免费试用   

linux下对apk使用ant 构建时,在import时提示失败,从错误信息来看,应该是相关包没有导入,但是在build文件中也尝试引入jar包,但还是报错,请各位大侠指点下。

 

详细错误信息如下:

 [javac] /home/xx/android/platform/packages/ss/product/application/settings/src/com/android/settings/AutoStandbyFragment.java:23: cannot find symbol
    [javac] symbol: class Fragment
    [javac] public class AutoStandbyFragment extends Fragment implements OnKeyListener {
    [javac]                                          ^
    [javac] /home/xx/android/platform/packages/ss/product/application/settings/src/com/android/settings/AutoStandbyFragment.java:23: cannot find symbol
    [javac] symbol: class OnKeyListener
    [javac] public class AutoStandbyFragment extends Fragment implements OnKeyListener {
    [javac]                                                              ^
    [javac]/home/xx/android/platform/packages/ss/product/application/settings/src/com/android/settings/AutoStandbyFragment.java:26: cannot find symbol
    [javac] symbol  : class EditText
    [javac] location: class com.android.settings.AutoStandbyFragment
    [javac]     private EditText mStandbyTimeEdit;
    [javac]             ^
    [javac]/home/xx/android/platform/packages/ss/product/application/settings/src/com/android/settings/AutoStandbyFragment.java:27: cannot find symbol
    [javac] symbol  : class Button
    [javac] location: class com.android.settings.AutoStandbyFragment
    [javac]     private Button mStandbyTimeButton;
    [javac]             ^
    [javac] /home/xx/android/platform/packages/ss/product/application/settings/src/com/android/settings
    [javac] symbol  : class McspCompCommun
    [javac] location: class com.android.settings.AutoStandbyFragment
    [javac]     private static McspCompCommun compCom = null;
    [javac]                    ^
    [javac] /home/xx/android/platform/packages/ss/product/application/settings/src/com/android/settings
    [javac] symbol  : class McspCfgmanager

 

 

build.xml文件配置如下:

 

<?xml version="1.0"?>

<project name="newSettings" basedir="." default="all">

 <!--You may notice that, I use location instead of value         -->
 <!--Both of them work correctly when I run ant -f build.xml    -->
 <!--But when this file is called by other ant file using ant task-->
 <!--In the junit task, the relative path cannot be parsed correctly-->
 <!--When using location, the path will be replaced with absolute path-->

 <!--The libs contains the emma.jar and emma_ant.jar-->
 <property name="libs" location="../lib" />

 <!--This is where we place our instrumented classes-->
 <property name="bin.instrument.dir" location="../instrbin" />

 <!--coverage metadata and report location-->
 <property name="coverage.dir" location="../coverage" />

 <!--junit report location-->
 <property name="junitReport.dir" location="../junitReport" />

 <!--main bin location-->
 <property name="bin.main.dir" location="../srcbin" />
 <!--test bin location-->
 <property name="bin.test.dir" location="../testbin" />
 <!--main source location-->
 <property name="src.main.dir" location="./src" />
 <!--test source location-->
 <property name="src.test.dir" location="./test" />

 <!--Instrument classes in this path-->
 <path id="classpath.main">
  <pathelement location="${bin.main.dir}" />
 </path>
 <!--Path where emma.jar and emma_ant.jar exist-->
 <path id="emma.lib">
  <pathelement location="${libs}/emma.jar" />
  <pathelement location="${libs}/emma_ant.jar" />
 </path>
 <!--enable emma-->
 <property name="emma.enabled" value="true" />
 <!--Add emma task to ant-->
 <taskdef resource="emma_ant.properties" classpathref="emma.lib" />

 <!--Default task-->
 <target name="all" depends="clean,compile-src.main,compile-src.test,
  instrument,test,gen-report-junit,gen-report-coverage">
 </target>
 
<property name="lib.dir" value="/home/xx/android/platform/out/target/product/sdk/dex_bootjars/system/framework"/>

 
<path id="compile.classpath">
<fileset dir="${lib.dir}" includes="./*.jar"/>
</path>

 

 <target name="compile-src.main">
  <mkdir dir="${bin.main.dir}" />
  <javac destdir="${bin.main.dir}" debug="on">
   <src path="${src.main.dir}" />
   <classpath refid="compile.classpath"/>
  </javac>
  <copy todir="${bin.main.dir}">
   <fileset dir="${src.main.dir}">
    <exclude name="**/*.java" />
   </fileset>
  </copy>
 </target>

 <target name="compile-src.test">
  <mkdir dir="${bin.test.dir}" />
  <javac destdir="${bin.test.dir}" debug="on">
   <src path="${src.test.dir}" />
   <classpath location="${bin.main.dir}" />
  </javac>
  <copy todir="${bin.test.dir}">
   <fileset dir="${src.test.dir}">
    <exclude name="**/*.java" />
   </fileset>
  </copy>
 </target>

 <!--Instrument the  src main bin, place the instrumented class in bin.instrument.dir-->
 <!--metadata file will be placed in coverage.dir-->
 <target name="instrument">
  <mkdir dir="${bin.instrument.dir}" />
  <mkdir dir="${coverage.dir}" />
  <emma enabled="${emma.enabled}">
   <instr instrpathref="classpath.main" destdir="${bin.instrument.dir}" metadatafile="${coverage.dir}/metadata.emma" merge="true">
   </instr>
  </emma>
  <copy todir="${bin.instrument.dir}">
   <fileset dir="${bin.main.dir}">
    <exclude name="**/*.java" />
   </fileset>
  </copy>
 </target>

 

 <!--Run test case, generate junit report and coverage report-->
 <target name="test">
  <mkdir dir="${junitReport.dir}" />


  <junit fork="true" forkmode="once" printsummary="withOutAndErr" errorproperty="test.error" showoutput="on">


   <!--Refer to metadata.emma to collect run information-->
   <jvmarg value="-Demma.coverage.out.file=${coverage.dir}/metadata.emma" />
   <jvmarg value="-Demma.coverage.out.merge=true" />

   <!--Test support package-->
   <classpath location="${bin.instrument.dir}" />

   <classpath location="${bin.test.dir}" />

   <classpath refid="emma.lib" />

   <formatter type="xml" />
   <!--Batch test exclude inner class-->
   <batchtest todir="${junitReport.dir}" haltonfailure="no">
    <fileset dir="${bin.test.dir}">
     <include name="**/*Test.class" />
    </fileset>
   </batchtest>
  </junit>

 </target>

 <target name="gen-report-junit">
  <!--Generate junit report-->
  <junitreport todir="${junitReport.dir}">
   <fileset dir="${junitReport.dir}">
    <include name="*" />
   </fileset>
   <report format="frames" todir="${junitReport.dir}" />
  </junitreport>
 </target>

 <!--Generate the  coverage report-->
 <target name="gen-report-coverage">
  <!-- if enabled, generate coverage report(s): -->
  <emma enabled="${emma.enabled}">
   <report sourcepath="${src.main.dir}" sort="+block,+name,+method,+class" metrics="method:70,block:80,line:80,class:100">
    <fileset dir="${coverage.dir}">
     <include name="*.emma" />
    </fileset>
    <html outfile="${coverage.dir}/coverage.html" depth="method" columns="name,class,method,block,line" />
   </report>
  </emma>
 </target>

 <!--Clean srcbin, instrumented bin,junit report, coverage report-->
 <target name="clean">
  <delete dir="${bin.instrument.dir}" />
  <delete dir="${coverage.dir}" />
  <delete dir="${junitReport.dir}" />
  <delete dir="${bin.main.dir}" />
  <delete dir="${bin.test.dir}" />
 </target>

</project>

 

 

举报
allison123
发帖于4年前 1回/1K+阅
顶部