【问题标题】:Execution failed for task ':app:transformClassesWithDexForDebug' while migrating project from eclipse to studio将项目从 Eclipse 迁移到工作室时,任务“:app:transformClassesWithDexForDebug”执行失败
【发布时间】:2016-09-17 17:48:46
【问题描述】:

我正在尝试在工作室中运行我的代码,但不断收到此错误:-

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
> Unexpected constructor structure.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

我尝试了很多方法来解决这个错误,但似乎没有什么对我有用

这是最初出现此错误时我的代码前面所做的事情:-

来自 FragmentActivity 的片段调用:-

  public void showSelectVideoFragment() {

        // TODO Auto-generated method stub
        if (checkCurrentSelectedBtForLeftMenu(lMenuBtUploadVideoWRAP)) {
            return;
        }

        setBtBackgroundForLeftMenu(lMenuBtUploadVideoWRAP);
        addFragment(new SVideoFragment(mLeftMenu));
    }

private void addFragment(Fragment fragment) {
        if (fragmentManager != null) {
            if (fragmentManager.getBackStackEntryCount() == 0) {
                PVHomeFragment homeFragment = (PVHomeFragment) fragmentManager
                        .findFragmentByTag(FM_TAG_HOME_FRAGMENT);
                fragmentManager.beginTransaction().hide(homeFragment).commit();

            } else {
                fragmentManager.popBackStack();
            }

            fragmentManager.beginTransaction()
                    .add(R.id.fragmentContainer, fragment, FM_TAG_TOP_FRAGMENT)
                    .addToBackStack(null).commit();
        }
    }

SVideoFragment 代码 :-

public class SVideoFragment extends PVBaseFragment {
private SlidingMenu mLeftMenu = null;
private static final String SLIDEMENU_KEY = "describable_key";

public SVideoFragment() {

}

@SuppressLint({"NewApi","ValidFragment"})
public SVideoFragment(SlidingMenu leftMenu) {
    mLeftMenu = leftMenu;
}


@Override
protected void initFragment() {
    // TODO Auto-generated method stub

}
@SuppressLint({"NewApi","ValidFragment"})
@Override
protected View initFragmentView(LayoutInflater inflater, ViewGroup container) {
    // TODO Auto-generated method stub
    View v = inflater.inflate(R.layout.fragment_select_video, container,
            false);

    Button btToggleLeftMenu = (Button) v
            .findViewById(R.id.btToggleLeftMenu);
    btToggleLeftMenu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            if (mLeftMenu != null) {
                mLeftMenu.toggle();
            }
        }
    });

    ((Button) v.findViewById(R.id.btSelectVideo))
            .setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    showVideoSelector();
                }
            });

    return v;
}

我在 build.gradle 中添加了以下几行:-

apply plugin: 'com.android.application'

            android {
                compileSdkVersion 23
                buildToolsVersion "23.0.2"

                defaultConfig {
                    applicationId "com.example.app"
                    minSdkVersion 14
                    targetSdkVersion 22
                    multiDexEnabled = true
                }

                 buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
        }
        lintOptions {
            abortOnError false
            checkReleaseBuilds false
        }
        dexOptions {
            javaMaxHeapSize "4g" //specify the heap size for the dex process
            preDexLibraries = false //delete the already predexed libraries
        }
        allprojects {
            configurations {


                all*.exclude group: 'com.android.support', module: 'support-v4'

            }
        }
    }

    dependencies {
    compile project(':sdk')
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile project(':android-3.1')
compile project(':AVIOCtrlDefine')
compile project(':Facebook')
compile project(':SlidingMenu-master')
compile 'com.google.android.gms:play-services-plus:8.4.0'
compile 'com.google.android.gms:play-services-auth:8.4.0'
compile 'com.google.android.gms:play-services-base:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
}
    android.packagingOptions {
        exclude 'the META-INF / DEPENDENCIES'
        exclude 'the META-INF / LICENSE'
        exclude 'the META-INF / LICENSE.txt'
        exclude 'the META-INF / license.txt'
        exclude 'the META-INF / NOTICE'
        exclude 'the META-INF / the NOTICE.txt '
        exclude ' the META-INF / NOTICE.txt '
        exclude ' the META-INF / ASL2.0 '
        exclude ' the META-INF / Services / javax.annotation.processing.Processor '
    }

在完成以上所有操作后,我仍然遇到同样的错误,所以我选择了第二种方法:-

我这样称呼 Fragment :-

public void showSelectVideoFragment() {
    SVideoFragment mSVideoFragment = new SVideoFragment();
    // TODO Auto-generated method stub
    if (checkCurrentSelectedBtForLeftMenu(lMenuBtUploadVideoWRAP)) {
        return;
    }

    setBtBackgroundForLeftMenu(lMenuBtUploadVideoWRAP);
    addFragment(mSVideoFragment.newInstance(mLeftMenu));
}

在片段中:-

 public class SVideoFragment extends PVBaseFragment {
    private SlidingMenu mLeftMenu = null;
    private static final String SLIDEMENU_KEY = "describable_key";

    public SVideoFragment() {

    }


    public static SVideoFragment newInstance(SlidingMenu leftMenu) {
        SVideoFragment fragment = new SVideoFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(SLIDEMENU_KEY, leftMenu);
        fragment.setArguments(bundle);

        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mLeftMenu = (SlidingMenu) getArguments().getSerializable(SLIDEMENU_KEY);
        }
    }

    @Override
    protected void initFragment() {
        // TODO Auto-generated method stub

    }
 @SuppressLint({"NewApi","ValidFragment"})
    @Override
    protected View initFragmentView(LayoutInflater inflater, ViewGroup container) {
        // TODO Auto-generated method stub
        View v = inflater.inflate(R.layout.fragment_select_video, container,
                false);

        Button btToggleLeftMenu = (Button) v
                .findViewById(R.id.btToggleLeftMenu);
        btToggleLeftMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                if (mLeftMenu != null) {
                    mLeftMenu.toggle();
                }
            }
        });

        ((Button) v.findViewById(R.id.btSelectVideo))
                .setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        showVideoSelector();
                    }
                });

        return v;
    }

但我仍然遇到同样的错误

** 当我在终端中运行 ./gradlew assembleDebug 时,我得到了:-**

  • 出了什么问题:任务 ':app:transformClassesWithDexForDebug' 执行失败。

    com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException:进程'命令 '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' 以非零结尾 退出值 1

这是我的应用程序依赖项:-

+--- 项目 :sdk +--- com.google.android.gms:play-services-ads:8.4.0 | --- com.google.android.gms:play-services-basement:8.4.0 | --- com.android.support:support-v4:23.0.0 | --- com.android.support:support-annotations:23.0.0 +--- 项目:android-3.1 +--- 项目 :AVIOCtrlDefine +--- 项目:Facebook | +--- com.android.support:support-v4:[21,22) -> 23.0.0 () | --- com.parse.bolts:bolts-android:1.1.4 +--- 项目:SlidingMenu-master +--- com.google.android.gms:play-services:8.4.0 | +--- com.google.android.gms:play-services-ads:8.4.0 () | +--- com.google.android.gms:play-services-analytics:8.4.0 | | --- com.google.android.gms:play-services-basement:8.4.0 () | +--- com.google.android.gms:play-services-appindexing:8.4.0 | | --- com.google.android.gms:play-services-base:8.4.0 | | --- com.google.android.gms:play-services-basement:8.4.0
(
) | +--- com.google.android.gms:play-services-appinvite:8.4.0 |
| --- com.google.android.gms:play-services-base:8.4.0 () |
+--- com.google.android.gms:play-services-appstate:8.4.0 | | --- com.google.android.gms:play-services-base:8.4.0 (
) | +--- com.google.android.gms:play-services-auth:8.4.0 | | --- com.google.android.gms:play-services-base:8.4.0 () | +--- com.google.android.gms:play-services-base:8.4.0 () | +--- com.google.android.gms:play-services-basement:8.4.0 () | +--- com.google.android.gms:play-services-cast:8.4.0 | | +--- com.google.android.gms:play-services-base:8.4.0 () | | --- com.android.support:mediarouter-v7:23.0.0 | | --- com.android.support:appcompat-v7:23.0.0 | | --- com.android.support:support-v4:23.0.0 () | +--- com.google.android.gms:play-services-drive:8.4.0 | | --- com.google.android.gms:play-services-base:8.4.0 () | +--- com.google.android.gms:play-services-fitness:8.4.0 | | +--- com.google.android.gms:play-services-base:8.4.0 () | | --- com.google.android.gms:play-services-location:8.4.0 | |
+--- com.google.android.gms:play-services-base:8.4.0 (
) | | --- com.google.android.gms:play-services-maps:8.4.0 | |
--- com.google.android.gms:play-services-base:8.4.0
() | +--- com.google.android.gms:play-services-games:8.4.0 | | +--- com.google.android.gms:play-services-base:8.4.0 () | | --- com.google.android.gms:play-services-drive:8.4.0 () | +--- com.google.android.gms:play-services-gcm:8.4.0 | | +--- com.google.android.gms:play-services-base:8.4.0 () | | --- com.google.android.gms:play-services-measurement:8.4.0 | |
--- com.google.android.gms:play-services-basement:8.4.0
() | +--- com.google.android.gms:play-services-identity:8.4.0 |
| --- com.google.android.gms:play-services-base:8.4.0 (
) |
+--- com.google.android.gms:play-services-location:8.4.0 () | +--- com.google.android.gms:play-services-maps:8.4.0 () | +--- com.google.android.gms:play-services-measurement:8.4.0 () | +--- com.google.android.gms:play-services-nearby:8.4.0 | | --- com.google.android.gms:play-services-base:8.4.0 () | +--- com.google.android.gms:play-services-panorama:8.4.0 | | --- com.google.android.gms:play-services-base:8.4.0 () | +--- com.google.android.gms:play-services-plus:8.4.0 | | --- com.google.android.gms:play-services-base:8.4.0 () | +--- com.google.android.gms:play-services-safetynet:8.4.0 | | --- com.google.android.gms:play-services-base:8.4.0 () | +--- com.google.android.gms:play-services-vision:8.4.0 | | --- com.google.android.gms:play-services-base:8.4.0 () | +--- com.google.android.gms:play-services-wallet:8.4.0 | | +--- com.google.android.gms:play-services-base:8.4.0 () | | +--- com.google.android.gms:play-services-identity:8.4.0 () | | --- com.google.android.gms:play-services-maps:8.4.0 () | --- com.google.android.gms:play-services-wearable:8.4.0 | --- com.google.android.gms:play-services-base:8.4.0 () --- com.android.support:multidex:1.0.0

更新:-

我已经尝试过每一件事,比如一个一个地添加 jars,还在 Android Studio 中创建了一个新项目,然后将所有文件夹放入其中,还过滤了项目所需的 google play 服务依赖项,添加了谷歌播放服务插件也包含 gcm.jason 文件。

在运行 ./gradlew assembleDebug --stacktrace 命令时

我得到了:-

错误:处理“java/awt/font/NumericShaper.class”时出现问题: 错误:对核心类(java.* 或 javax.*)

我已经对这个错误进行了一些搜索,发现它似乎是由于项目中的 android.jar 复制而出现的,但我在我的依赖项中没有找到任何重复的文件。

这是我更新的 gradle.build 文件:-

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.petzview.android"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
        checkReleaseBuilds false
    }

    dexOptions {
        incremental = true;
        maxProcessCount 4
        javaMaxHeapSize "4g"
        dexInProcess = false
        preDexLibraries = false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.android.gms:play-services-ads:9.0.0'
    compile 'com.google.android.gms:play-services-plus:9.0.0'
    compile 'com.google.android.gms:play-services-gcm:9.0.0'
    compile project(':AVIOCtrlDefine')
    compile project(':Facebook')
    compile project(':SlidingMenu-master')
    compile 'com.android.support:multidex:1.0.1'
}
android.packagingOptions {
    exclude 'the META-INF / DEPENDENCIES'
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'the META-INF / LICENSE'
    exclude 'the META-INF / LICENSE.txt'
    exclude 'the META-INF / license.txt'
    exclude 'the META-INF / NOTICE'
    exclude 'the META-INF / the NOTICE.txt '
    exclude ' the META-INF / NOTICE.txt '
    exclude ' the META-INF / ASL2.0 '
    exclude ' the META-INF / Services / javax.annotation.processing.Processor '
}
apply plugin: 'com.google.gms.google-services'

谁能建议我在android studio中解决这个问题的方法。

【问题讨论】:

  • 任何,请建议,我真的卡住了吗?
  • 在 gradlew 输出的更高位置,你能看到来自失败的 java 进程的任何错误消息吗?
  • 嘿,@MarcinKoziński 这就是我得到的信息:Gradle 任务 [:app:assembleDebug] 在不一致的位置 '/home/ravi/adt_lollipops 中观察到包 id 'build-tools;20.0.0' /adt-bundle-linux-x86_64-20140702/sdk/build-tools/android-4.4W'(预期'/home/ravi/adt_lollipops/adt-bundle-linux-x86_64-20140702/sdk/build-tools/20.0. 0')
  • 我刚刚将 android-4.4W 的名称更改为 20.0.0 但现在它开始给我错误 Task 'assembleDebugTest' not found in project ':app'。
  • 有时,在更改依赖项版本后,我在构建过程中会遇到类似的 Gradle 错误。对我来说,solutuion 完全不涉及项目。

标签: android-fragments android-studio constructor


【解决方案1】:
【解决方案2】:

试试这个:(这看起来可能是问题)

public SVideoFragment() {
    super();
}

@SuppressLint({"NewApi","ValidFragment"})
public SVideoFragment(SlidingMenu leftMenu) {
    this();
    mLeftMenu = leftMenu;
}

更多信息:Difference between "this" and"super" keywords in Java

【讨论】:

  • 您好 Flummox,感谢您的回复,我仍然收到上述错误“任务 ':app:transformClassesWithDexForDebug' 执行失败。”
  • 我认为“app:transformClassesWithDexForDebug”是您的应用程序的名称?您在错误中的某处看到片段或类名称吗?看起来你需要检查你使用的所有类,看看构造函数是否做了他们应该做的......希望它们不会太多。
【解决方案3】:

嘿,这个项目是从 eclipse 迁移到 studio 吗?我遇到了同样的错误。我通过制作项目 multidex 解决了它。之后重新构建并同步它。希望这会有所帮助。删除重复的依赖项。

gradle - library duplicates in dependencies

【讨论】:

  • 是的,这正是从eclipse迁移到studio的项目
  • 顺便说一下,我已经在 defaultConfig 下添加了 multiDexEnabled * true* ,请查看我上面提到的 gradle
【解决方案4】:

我的问题是这个有点不寻常的构造函数

public ActionRequest(BridgeActivity bridgeActivity, String url, Response.Listener<RestResult> listener) {
    super(url, Method.POST, RestResult.class, bridgeActivity.new ResponseListener<RestResult>() {
        @Override
        public void onResponse(RestResult response) {
            listener.onResponse(response);
        }
    });

我认为该构造函数中的 bidgeActivity.new ResponseListener&lt;RestResult&gt;() 调用是不允许的,我猜该构造不是由 dex 编译器中的某些代码生成器实现的。

【讨论】:

    猜你喜欢
    • 2016-12-28
    • 2016-04-22
    • 2016-02-16
    • 2016-10-01
    • 2016-12-18
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    相关资源
    最近更新 更多