菜鸟提问:linux 下面使用ant构建apk失败

发布于 2021-11-27 09:37:01 字数 11359 浏览 839 评论 3

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>

 

 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌上芳菲 2021-11-28 22:51:19

跪谢答复! 但是还有问题,看了我们的工程,android/platform下有sdk目录,但是没有folder目录,也没搜索到android.sh,是不是编译服务器没有安装sdk,但是为什么又可以编译工程呢?

温柔少女心 2021-11-28 22:10:09

回复
http://developer.android.com/tools/projects/projects-cmdline.html

反目相谮 2021-11-27 20:41:13

为什么自己写build.xml?

$android/sdk/folder/android.sh -update-project path/to/project

这个会帮你生成build.xml

你可以先去看看sdk tools文档

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文