我正在尝试在Studio中运行代码,但是不断收到此错误:-
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时,我得到了:-**
这是我的应用程序依赖项:-
更新:-
我已经尝试了所有的事情,例如一个 jar 一个 jar 地添加,也已经在Android Studio中创建了一个新项目,然后将所有文件夹放入其中,还过滤了项目所需的google play服务依赖项,为google添加了插件使用gcm.jason文件也可以播放服务。
在运行 ./gradlew assembleDebug --stacktrace 命令时
我正在获得:-
我已经完成了一些与此错误相关的搜索,发现它似乎是由于项目中的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中解决此问题的方法吗?
最佳答案
我遇到了同样的问题,并使用disabling Instant Run in Android Studio -> Preferences (search for "instant run" or) -> "Build, Execution, Deployment" -> Instant Run -> Enable Instant Run -> turn off进行了修复
感谢@Balki的回答!
关于android-fragments - 将项目从Eclipse迁移到Studio时,任务 ':app:transformClassesWithDexForDebug'的执行失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37347082/