简体   繁体   English

android错误:任务执行失败':app:packageDebug'

[英]android Error:Execution failed for task ':app:packageDebug'

my function 我的功能

    public static String postFile(String url,String fileName, String userName) throws Exception {

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(url);
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

    final File file = new File(fileName);

    ContentBody cfile=new FileBody(file);
    builder.addPart("file",cfile);
    builder.addTextBody("userName", userName);

    final HttpEntity yourEntity = builder.build();

    class ProgressiveEntity implements HttpEntity {
        @Override
        public void consumeContent() throws IOException {
            yourEntity.consumeContent();
        }
        @Override
        public InputStream getContent() throws IOException,
                IllegalStateException {
            return yourEntity.getContent();
        }
        @Override
        public Header getContentEncoding() {
            return yourEntity.getContentEncoding();
        }
        @Override
        public long getContentLength() {
            return yourEntity.getContentLength();
        }
        @Override
        public Header getContentType() {
            return yourEntity.getContentType();
        }
        @Override
        public boolean isChunked() {
            return yourEntity.isChunked();
        }
        @Override
        public boolean isRepeatable() {
            return yourEntity.isRepeatable();
        }
        @Override
        public boolean isStreaming() {
            return yourEntity.isStreaming();
        } // CONSIDER put a _real_ delegator into here!

        @Override
        public void writeTo(OutputStream outstream) throws IOException {

            class ProxyOutputStream extends FilterOutputStream {
                /**
                 * @author Stephen Colebourne
                 */

                public ProxyOutputStream(OutputStream proxy) {
                    super(proxy);
                }
                public void write(int idx) throws IOException {
                    out.write(idx);
                }
                public void write(byte[] bts) throws IOException {
                    out.write(bts);
                }
                public void write(byte[] bts, int st, int end) throws IOException {
                    out.write(bts, st, end);
                }
                public void flush() throws IOException {
                    out.flush();
                }
                public void close() throws IOException {
                    out.close();
                }
            } // CONSIDER import this class (and risk more Jar File Hell)

            class ProgressiveOutputStream extends ProxyOutputStream {
                public ProgressiveOutputStream(OutputStream proxy) {
                    super(proxy);
                }
                public void write(byte[] bts, int st, int end) throws IOException {

                    // FIXME  Put your progress bar stuff here!

                    out.write(bts, st, end);
                }
            }

            yourEntity.writeTo(new ProgressiveOutputStream(outstream));
        }

    };
    ProgressiveEntity myEntity = new ProgressiveEntity();

    post.setEntity(myEntity);
    HttpResponse response = client.execute(post);

    return getContent(response);

}

public static String getContent(HttpResponse response) throws IOException {
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String body = "";
    String content = "";

    while ((body = rd.readLine()) != null)
    {
        content += body + "\n";
    }
    return content.trim();
}

my gradle dependencies 我的gradle依赖

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'

compile "org.apache.httpcomponents:httpmime:4.3.6"
compile "org.apache.httpcomponents:httpclient:4.3.6"
compile "org.apache.httpcomponents:httpcore:4.2.4"

} }

build run error message: 构建运行错误消息:

Error:Execution failed for task ':app:packageDebug'.

Duplicate files copied in APK META-INF/DEPENDENCIES File 1: /home/bekir/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3.3.jar File 2: /home/bekir/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3.3.jar } } android { packagingOptions { exclude 'META-INF/DEPENDENCIES' You can ignore those files in your build.gradle: Origin 2: /home/bekir/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.6/cf8bacbf0d476c7f2221f861269365b66447f7ec/httpmime-4.3.6.jar Origin 1: /home/bekir/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3.3.jar Path in archive: META-INF/DEPENDENCIES :app:packageDebug Error:duplicate files during packaging of APK /home/bekir/AndroidStudioProjects/uploadfile/app/build/outputs/apk/app-debug-unaligned.apk :app:validat 在APK META-INF / DEPENDENCIES文件1中复制的重复文件:/home/bekir/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3.3 .jar文件2:/home/bekir/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3.3.jar}} android {packagingOptions {排除'META-INF / DEPENDENCIES'你可以忽略build.gradle中的那些文件:Origin 2:/home/bekir/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3。 6 / cf8bacbf0d476c7f2221f861269365b66447f7ec / httpmime-4.3.6.jar Origin 1:/home/bekir/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3。 3.jar归档中的路径:META-INF / DEPENDENCIES:app:packageDebug错误:在打包APK /home/bekir/AndroidStudioProjects/uploadfile/app/build/outputs/apk/app-debug-unaligned.apk期间重复文件:app :validat eDebugSigning :app:processDebugJavaRes UP-TO-DATE :app:dexDebug UP-TO-DATE :app:preDexDebug UP-TO-DATE :app:compileDebugJava UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:processDebugManifest UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:compileDebugAidl UP-TO-DATE :app:prepareDebugDependencies :app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72103Library UP-TO-DATE :app:preReleaseBuild :app:preDebugBuild :app:compileDebugNdk UP-TO-DATE :app:checkDebugManifest :app:preBuild eDebugSigning:app:processDebugJavaRes UP-TO-DATE:app:dexDebug UP-TO-DATE:app:preDexDebug UP-TO-DATE:app:compileDebugJava UP-TO-DATE:app:generateDebugSources UP-TO-DATE:app:processDebugResources最新消息:app:processDebugManifest UP-TO-DATE:app:mergeDebugResources UP-TO-DATE:app:generateDebugResources UP-TO-DATE:app:generateDebugResValues UP-TO-DATE:app:mergeDebugAssets UP-TO-DATE :app:generateDebugAssets UP-TO-DATE:app:generateDebugBuildConfig UP-TO-DATE:app:compileDebugRenderscript UP-TO-DATE:app:compileDebugAidl UP-TO-DATE:app:prepareDebugDependencies:app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE: app:prepareComAndroidSupportAppcompatV72103Library UP-TO-DATE:app:preReleaseBuild:app:preDebugBuild:app:compileDebugNdk UP-TO-DATE:app:checkDebugManifest:app:preBuild

Warning:Dependency org.apache.httpcomponents:httpclient:4.3.6 is ignored for release as it may be conflicting with the internal version provided by Android. 警告:依赖org.apache.httpcomponents:httpclient:4.3.6因发布而被忽略,因为它可能与Android提供的内部版本冲突。 In case of problem, please repackage it with jarjar to change the class packages In case of problem, please repackage it with jarjar to change the class packages Warning:Dependency org.apache.httpcomponents:httpclient:4.3.6 is ignored for release as it may be conflicting with the internal version provided by Android. 如果出现问题,请用jarjar重新打包以更改类包。如果出现问题,请用jarjar重新打包以更改类包警告:依赖org.apache.httpcomponents:httpclient:4.3.6因发布而被忽略可能与Android提供的内部版本冲突。 In case of problem, please repackage it with jarjar to change the class packages Warning:Dependency org.apache.httpcomponents:httpclient:4.3.6 is ignored for debug as it may be conflicting with the internal version provided by Android. 如果出现问题,请使用jarjar重新打包以更改类包警告:依赖org.apache.httpcomponents:httpclient:4.3.6因调试而被忽略,因为它可能与Android提供的内部版本冲突。 In case of problem, please repackage it with jarjar to change the class packages Information:Gradle tasks [:app:assembleDebug] Warning:Dependency org.apache.httpcomponents:httpclient:4.3.6 is ignored for debug as it may be conflicting with the internal version provided by Android. 如果出现问题,请用jarjar重新打包以更改类包信息:Gradle tasks [:app:assembleDebug]警告:依赖org.apache.httpcomponents:httpclient:4.3.6因调试而被忽略,因为它可能与Android提供的内部版本。

Error:Execution failed for task ':app:packageDebug'.

Duplicate files copied in APK META-INF/DEPENDENCIES File 1: /home/bekir/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3.3.jar File 2: /home/bekir/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3.3.jar 在APK META-INF / DEPENDENCIES文件1中复制的重复文件:/home/bekir/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3.3 .jar文件2:/home/bekir/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.3.3/f91b7a4aadc5cf486df6e4634748d7dd7a73f06d/httpcore-4.3.3.jar

For the duplicated files error use: 对于重复文件错误,请使用:

packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
}

it shoud resolve many "Duplicate files" not only with apache's libs and the dependency error can be ignored. 它不仅可以解决许多“重复文件”与apache的libs,并且可以忽略依赖性错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android:任务 ':app:packageDebug' 执行失败。 > 数据 - Android: Execution failed for task ':app:packageDebug'. > data 错误:任务':app:packageDebug'的执行失败 - Error: Execution failed for task ':app:packageDebug' 任务':app:packageDebug'的执行失败 - Execution failed for task ':app:packageDebug' 尝试构建apk-错误:任务':app:packageDebug'执行失败 - Trying to build apk - Error:Execution failed for task ':app:packageDebug' react native cli run android 上的任务“:app:packageDebug”执行失败 - Execution failed for task ':app:packageDebug' on react native cli run android 错误:任务 ':app:packageDebug' 执行失败。 >.zip.isFile() - Error:Execution failed for task ':app:packageDebug'. > !zip.isFile() 错误:任务 ':app:packageDebug' 的执行失败 - Java 堆空间 - Error:Execution failed for task ':app:packageDebug' - Java heap space 错误:gradle 版本 3.5.2 的任务 ':app:packageDebug' 执行失败 - Error:Execution failed for task ':app:packageDebug' for gradle version 3.5.2 错误:任务':app:packageDebug'的执行失败。 > com.android.builder.packaging.PackagerException - Error:Execution failed for task ':app:packageDebug'. > com.android.builder.packaging.PackagerException Flutter:任务':app:packageDebug'的执行失败 - Flutter: Execution failed for task ':app:packageDebug'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM