2

我正在使用 ant 从命令提示符编译 android 项目。但是当我用 ant 编译时,我在转换为 dex 文件时遇到了这个错误。

-dex:
      [dex] Converting compiled files and external libraries into E:\Demo\bin\classes.dex...
       [dx]
       [dx] trouble writing output: Too many methods: 66156; max is 65536. By package:
       [dx]     26 android
       [dx]     83 android.accessibilityservice
       [dx]    410 android.accounts
       [dx]    430 android.animation
       [dx]      8 android.annotation
       [dx]   3695 android.app
       [dx]    404 android.app.admin
       [dx]    309 android.app.backup
       [dx]     95 android.appwidget
       [dx]   1248 android.bluetooth
       [dx]   1673 android.content
       [dx]    932 android.content.pm
       [dx]    503 android.content.res
       [dx]    522 android.database
       [dx]    394 android.database.sqlite
       [dx]     91 android.ddm
       [dx]      5 android.debug
       [dx]     45 android.dirEncryption
       [dx]    163 android.drm
       [dx]     51 android.drm.mobile1
       [dx]     30 android.emoji
       [dx]   1245 android.graphics
       [dx]    705 android.graphics.drawable
       [dx]     36 android.graphics.drawable.shapes
       [dx]    321 android.hardware
       [dx]     96 android.hardware.motion
       [dx]    187 android.hardware.usb
       [dx]     43 android.icu.text
       [dx]    436 android.inputmethodservice
       [dx]    614 android.location
       [dx]   1526 android.media
       [dx]    248 android.media.audiofx
       [dx]    500 android.media.videoeditor
       [dx]    134 android.mtp
       [dx]   1547 android.net
       [dx]    375 android.net.http
       [dx]     49 android.net.rtp
       [dx]    440 android.net.sip
       [dx]   1529 android.net.wifi
       [dx]    493 android.net.wifi.p2p
       [dx]      1 android.net.wimax
       [dx]    357 android.nfc
       [dx]    165 android.nfc.tech
       [dx]   1501 android.opengl
       [dx]   2156 android.os
       [dx]    301 android.os.storage
       [dx]    468 android.preference
       [dx]    589 android.provider
       [dx]    916 android.renderscript
       [dx]     35 android.sax
       [dx]    140 android.sec.clipboard
       [dx]     52 android.sec.clipboard.data
       [dx]     31 android.sec.clipboard.data.file
       [dx]     58 android.sec.clipboard.data.list
       [dx]     31 android.sec.clipboard.util
       [dx]    372 android.sec.enterprise
       [dx]      5 android.sec.enterprise.kioskmode
       [dx]    565 android.sec.multiwindow
       [dx]     64 android.sec.mwdialog
       [dx]    113 android.security
       [dx]    720 android.server
       [dx]    123 android.service.wallpaper
       [dx]    147 android.speech
       [dx]    458 android.speech.tts
       [dx]    487 android.telephony
       [dx]     16 android.telephony.cdma
       [dx]    143 android.telephony.gsm
       [dx]    729 android.text
       [dx]     93 android.text.format
       [dx]    372 android.text.method
       [dx]    252 android.text.style
       [dx]     43 android.text.util
       [dx]    618 android.util
       [dx]     45 android.util.safelog
       [dx]     63 android.util.secutil
       [dx]   3897 android.view
       [dx]    314 android.view.accessibility
       [dx]    226 android.view.animation
       [dx]    319 android.view.inputmethod
       [dx]    112 android.view.textservice
       [dx]   3963 android.webkit
       [dx]   5621 android.widget
       [dx]     12 com.android.i18n.phonenumbers
       [dx]      2 com.android.i18n.phonenumbers.geocoding
       [dx]     23 com.android.internal
       [dx]    627 com.android.internal.app
       [dx]     80 com.android.internal.appwidget
       [dx]     57 com.android.internal.content
       [dx]     23 com.android.internal.database
       [dx]      8 com.android.internal.http
       [dx]     37 com.android.internal.location
       [dx]     12 com.android.internal.logging
       [dx]     49 com.android.internal.net
       [dx]    649 com.android.internal.os
       [dx]     26 com.android.internal.os.storage
       [dx]     54 com.android.internal.policy
       [dx]    194 com.android.internal.statusbar
       [dx]   3499 com.android.internal.telephony
       [dx]    675 com.android.internal.telephony.cat
       [dx]    922 com.android.internal.telephony.cdma
       [dx]    101 com.android.internal.telephony.cdma.sms
       [dx]   1056 com.android.internal.telephony.gsm
       [dx]    662 com.android.internal.telephony.ims
       [dx]      7 com.android.internal.telephony.mosecurity
       [dx]    474 com.android.internal.telephony.sip
       [dx]     15 com.android.internal.telephony.test
       [dx]     88 com.android.internal.textservice
       [dx]    393 com.android.internal.util
       [dx]    435 com.android.internal.view
       [dx]    509 com.android.internal.view.menu
       [dx]    695 com.android.internal.widget
       [dx]      1 com.android.org.bouncycastle.asn1
       [dx]      4 com.android.org.bouncycastle.asn1.x509
       [dx]      3 com.android.org.bouncycastle.jce.netscape
       [dx]      6 com.android.org.bouncycastle.openssl
       [dx]      1 com.android.org.bouncycastle.util.encoders
       [dx]     36 com.android.server
       [dx]     10 com.google.android.collect
       [dx]    313 com.google.android.gles_jni
       [dx]     11 com.lguplus.se
       [dx]     26 com.samsung
       [dx]     67 com.samsung.ScreenCapture
       [dx]    164 com.samsung.bluetoothle
       [dx]    100 com.samsung.media.fmradio
       [dx]    224 com.samsung.media.fmradio.internal
       [dx]    338 com.samsung.wfd
       [dx]     40 com.sec.android.app
       [dx]     41 com.sec.android.app.IWSpeechRecognizer
       [dx]    170 com.sec.android.app.eg
       [dx]    341 com.sec.android.app.eg.activity
       [dx]     21 com.sec.android.app.eg.cache
       [dx]     12 com.sec.android.app.eg.database
       [dx]      7 com.sec.android.app.eg.download
       [dx]     62 com.sec.android.app.eg.fragment
       [dx]     94 com.sec.android.app.eg.http
       [dx]     28 com.sec.android.app.eg.os
       [dx]      4 com.sec.android.app.eg.parser
       [dx]     15 com.sec.android.app.eg.parser.evergalade
       [dx]    311 com.sec.android.app.eg.parser.mediahub
       [dx]     12 com.sec.android.app.eg.request
       [dx]     27 com.sec.android.app.eg.request.get
       [dx]     19 com.sec.android.app.eg.request.post
       [dx]     10 com.sec.android.app.eg.screen
       [dx]      1 com.sec.android.app.eg.screen.land
       [dx]     46 com.sec.android.app.eg.service
       [dx]    335 com.sec.android.app.eg.util
       [dx]     51 com.sec.android.app.eg.view
       [dx]    131 com.sec.android.app.eg.view.ebookhub
       [dx]    129 com.sec.android.app.eg.view.gamehub
       [dx]    127 com.sec.android.app.eg.view.mediahub
       [dx]    124 com.sec.android.app.eg.view.musichub
       [dx]    180 com.sec.android.app.eg.view.mymedia
       [dx]     56 com.sec.android.app.eg.widget
       [dx]     50 com.sec.android.facedetection
       [dx]     10 com.sec.android.ims
       [dx]    210 com.sec.android.internal.ims
       [dx]    186 com.sec.android.internal.ims.external
       [dx]      1 dalvik.bytecode
       [dx]     65 dalvik.system
       [dx]      7 dalvik.system.profiler
       [dx]      4 default
       [dx]    252 java.io
       [dx]    447 java.lang
       [dx]      8 java.lang.ref
       [dx]     24 java.lang.reflect
       [dx]      4 java.math
       [dx]    108 java.net
       [dx]     94 java.nio
       [dx]      9 java.nio.channels
       [dx]     13 java.nio.charset
       [dx]     23 java.security
       [dx]     17 java.security.cert
       [dx]      1 java.security.spec
       [dx]     39 java.text
       [dx]    372 java.util
       [dx]     62 java.util.concurrent
       [dx]     20 java.util.concurrent.atomic
       [dx]     12 java.util.concurrent.locks
       [dx]     12 java.util.jar
       [dx]     13 java.util.logging
       [dx]     15 java.util.regex
       [dx]     11 java.util.zip
       [dx]      9 javax.crypto
       [dx]      1 javax.crypto.spec
       [dx]     33 javax.microedition.khronos.egl
       [dx]    267 javax.microedition.khronos.opengles
       [dx]     30 javax.net.ssl
       [dx]      1 javax.security.auth.x500
       [dx]      2 javax.sip
       [dx]     11 javax.sip.address
       [dx]      4 junit.framework
       [dx]      6 libcore.icu
       [dx]      2 libcore.internal
       [dx]     17 libcore.io
       [dx]      4 libcore.net
       [dx]      7 libcore.net.http
       [dx]      2 libcore.util
       [dx]      2 org.apache.commons.codec.binary
       [dx]     16 org.apache.harmony.dalvik.ddmc
       [dx]      2 org.apache.harmony.luni.internal.util
       [dx]      2 org.apache.harmony.security.asn1
       [dx]      6 org.apache.harmony.security.pkcs7
       [dx]      2 org.apache.harmony.security.provider.cert
       [dx]      1 org.apache.harmony.xml
       [dx]     11 org.apache.harmony.xnet.provider.jsse
       [dx]     33 org.apache.http
       [dx]     10 org.apache.http.client
       [dx]      2 org.apache.http.client.entity
       [dx]      8 org.apache.http.client.methods
       [dx]      1 org.apache.http.client.params
       [dx]      1 org.apache.http.conn
       [dx]      2 org.apache.http.conn.routing
       [dx]      4 org.apache.http.conn.scheme
       [dx]      2 org.apache.http.conn.ssl
       [dx]      1 org.apache.http.conn.util
       [dx]      9 org.apache.http.entity
       [dx]      3 org.apache.http.impl
       [dx]      8 org.apache.http.impl.client
       [dx]      1 org.apache.http.impl.conn
       [dx]      3 org.apache.http.impl.conn.tsccm
       [dx]      3 org.apache.http.impl.entity
       [dx]      6 org.apache.http.impl.io
       [dx]      6 org.apache.http.io
       [dx]     16 org.apache.http.message
       [dx]     14 org.apache.http.params
       [dx]      9 org.apache.http.protocol
       [dx]      8 org.apache.http.util
       [dx]      3 org.ccil.cowan.tagsoup
       [dx]     25 org.json
       [dx]      2 org.kxml2.io
       [dx]     13 org.xml.sax
       [dx]      1 org.xml.sax.helpers
       [dx]     31 org.xmlpull.v1

BUILD FAILED
D:\DevTools\android-sdk-windows\tools\ant\build.xml:851: The following error occurred while executing this line:
D:\DevTools\android-sdk-windows\tools\ant\build.xml:853: The following error occurred while executing this line:
D:\DevTools\android-sdk-windows\tools\ant\build.xml:865: The following error occurred while executing this line:
D:\DevTools\android-sdk-windows\tools\ant\build.xml:266: null returned: 2

请帮助我,如何解决这个问题?

这是我的 build.xml 文件

<!-- The local.properties file is created and updated by the 'android' tool.
     It contains the path to the SDK. It should *NOT* be checked into
     Version Control Systems. -->
<property file="local.properties" />

<!-- The ant.properties file can be created by you. It is only edited by the
     'android' tool to add properties to it.
     This is the place to change some Ant specific build properties.
     Here are some properties you may want to change/update:

     source.dir
         The name of the source directory. Default is 'src'.
     out.dir
         The name of the output directory. Default is 'bin'.

     For other overridable properties, look at the beginning of the rules
     files in the SDK, at tools/ant/build.xml

     Properties related to the SDK location or the project target should
     be updated using the 'android' tool with the 'update' action.

     This file is an integral part of the build system for your
     application and should be checked into Version Control Systems.

     -->
<property file="ant.properties" />

<!-- if sdk.dir was not set from one of the property file, then
     get it from the ANDROID_HOME env var.
     This must be done before we load project.properties since
     the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
    <isset property="env.ANDROID_HOME" />
</condition>

<!-- The project.properties file is created and updated by the 'android'
     tool, as well as ADT.

     This contains project specific properties such as project target, and library
     dependencies. Lower level build properties are stored in ant.properties
     (or in .classpath for Eclipse projects).

     This file is an integral part of the build system for your
     application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />

<!-- quick check on sdk.dir -->
<fail
        message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
        unless="sdk.dir"
/>

<!--
    Import per project custom build rules if present at the root of the project.
    This is the place to put custom intermediary targets such as:
        -pre-build
        -pre-compile
        -post-compile (This is typically used for code obfuscation.
                       Compiled code location: ${out.classes.absolute.dir}
                       If this is not done in place, override ${out.dex.input.absolute.dir})
        -post-package
        -post-build
        -pre-clean
-->
<import file="custom_rules.xml" optional="true" />

<!-- Import the actual build file.

     To customize existing targets, there are two options:
     - Customize only one target:
         - copy/paste the target into this file, *before* the
           <import> task.
         - customize it to your needs.
     - Customize the whole content of build.xml
         - copy/paste the content of the rules files (minus the top node)
           into this file, replacing the <import> task.
         - customize to your needs.

     ***********************
     ****** IMPORTANT ******
     ***********************
     In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
     in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />

4

1 回答 1

1

在我看来,您正在尝试将其编译android.jar到您的包中。如果不了解您的项目/构建脚本是如何设置的,则很难给出完整的答案:

确保您没有专门添加android.jar到您的构建路径中。

于 2012-08-07T14:27:03.453 回答