Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragment cannot be cast to android.support.v4.app.Fragment #378

Open
TongWeiLe opened this issue Oct 3, 2017 · 10 comments
Open

Fragment cannot be cast to android.support.v4.app.Fragment #378

TongWeiLe opened this issue Oct 3, 2017 · 10 comments

Comments

@TongWeiLe
Copy link

问题详细描述 Detailed description of the problem

要打开的插件Fragment继承了Fragment.jar中的V4Fragment,但还是报了这个问题,怎么解决?

复现问题步骤 Steps to reproduce the problem

其它重要信息 Other important information

replugin-host-lib/gradle Version:2.2.0
rePlugin-plugin-lib/gradle Version:2.2.0

Android API Version:5.1
Android 手机型号&ROM(Phone model & ROM):

Logcat上下文 Logcat context

@1321365765
Copy link

1321365765 commented Oct 17, 2017

gradle 编译的时候把v4包移除就行了
exclude(group: 'com.android.support', module: 'support-v4')

@ByEric
Copy link

ByEric commented Oct 20, 2017

碰到同样的问题,请问您解决了嘛 @TongWeiLe
.mvp.ui.fragment.home.HomeFragment cannot be cast to android.support.v4.app.Fragment

@1321365765
Copy link

把demo里面libs下面的fragment包加到你的项目中去provided files('libs/fragment.jar')//这个jar就是从Support-fragment中提取出来的并非特制包目的是为了骗过编译期
这个只会参与编译不会打包到apk里。
只要插件没有引用到v4包就行了。在host里使用的时候就是用主的包下的fragment了。
注意v7包就已经引入的v4包,可以使用exclude(group: 'com.android.support', module: 'support-v4')移除

@ByEric
Copy link

ByEric commented Oct 23, 2017

@1321365765 插件中已经provided files('libs/fragment.jar')了,并exclude(group: 'com.android.support', module: 'support-v4')移除v4包,为什么还会报这个错误

@1321365765
Copy link

@ByEric 可以发下插件的build.gradle
dependencies{
..
}
出来看下吗
除了v7包,应该还有其他library 引用了v4包

@ByEric
Copy link

ByEric commented Oct 23, 2017

@1321365765
dependencies {
compile files('libs/zxing.jar')
compile project(':pickerview')
compile files('libs/tbs_sdk_thirdapp_v3.1.0.1034_43100_sharewithdownload_obfs_20170301_182143.jar')
compile files('libs/jsms_android-1.1.0.jar')
compile files('libs/permissionUtil.jar')
compile files('libs/MobCommons-2017.0608.1618.jar')
compile files('libs/ShareSDK-Core-3.0.0.jar')
compile files('libs/ShareSDK-QQ-3.0.0.jar')
compile files('libs/ShareSDK-SinaWeibo-3.0.0.jar')
compile files('libs/ShareSDK-Wechat-3.0.0.jar')
compile files('libs/ShareSDK-Wechat-Core-3.0.0.jar')
compile files('libs/ShareSDK-Wechat-Moments-3.0.0.jar')
compile files('libs/MobTools-2017.0608.1618.jar')

provided files('libs/fragment.jar')//这个jar就是从Support-fragment中提取出来的并非特制包目的是为了骗过编译期

compile('com.android.support:appcompat-v7:24.2.0') {
    exclude group: 'com.android.support', module: 'support-v4'
}
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:support-v4:24.2.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
compile 'com.android.support:percent:24.2.0'

compile 'com.jakewharton:butterknife:8.0.1'
compile 'com.google.dagger:dagger:2.2'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.5'
compile 'com.tbruyelle.rxpermissions:rxpermissions:0.7.0@aar'
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.retrofit2:converter-jackson:2.0.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.8.1'
compile 'com.squareup.okio:okio:1.6.0'
compile 'com.github.zhaokaiqiang.klog:library:1.4.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'de.greenrobot:greendao:1.3.7'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'com.dmitrymalkovich.android:material-design-dimens:1.2'
compile 'com.jakewharton.rxbinding:rxbinding-recyclerview-v7:0.4.0'
compile 'com.github.chrisbanes:PhotoView:1.2.6'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1@aar'
compile 'com.daimajia.androidanimations:library:1.1.3@aar'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.zcw:togglebutton-library:1.0.0'
compile 'com.amap.api:map2d:latest.integration'
compile 'com.amap.api:3dmap:latest.integration'
compile('com.amap.api:search:latest.integration') {
    exclude group: 'com.amap.api.services', module: 'a'
}
compile 'com.amap.api:location:latest.integration'
compile 'com.makeramen:roundedimageview:2.3.0'
compile 'com.apkfuns.logutils:library:1.5.1.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.kyleduo.switchbutton:library:1.4.6'
compile 'cn.jiguang.sdk:jpush:3.0.3'
compile 'cn.jiguang.sdk:jcore:1.1.1'
compile 'com.jcodecraeer:xrecyclerview:1.3.2'
compile 'com.google.firebase:firebase-core:9.0.0'
compile 'com.google.firebase:firebase-crash:9.0.0'
testCompile 'junit:junit:4.12'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
apt 'com.google.dagger:dagger-compiler:2.2'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
provided 'org.glassfish:javax.annotation:10.0-b28'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
compile 'com.umeng.analytics:analytics:latest.integration'
compile 'com.allenliu.versionchecklib:library:1.6.5'
compile 'com.qihoo360.replugin:replugin-plugin-lib:2.2.1'

}

@1321365765
Copy link

1321365765 commented Oct 23, 2017

@ByEric
support:design 已经引用了v7包了 v7有包又引用了v4包
可以看下这个 http://www.paincker.com/gradle-dependencies
其他项目有没有引用v4包
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
配置这个应该可以解决你的这个问题

@longforus
Copy link

@1321365765
插件依赖的
implementation'com.alibaba.android:vlayout:1.0.9'
implementation'com.alibaba.android:ultraviewpager:1.0.4'
里面依赖了v4包,
我添加了
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
之后打开生成的dex发现里面还是有v4包的内容,我的插件又必须使用上面的库 这个怎么解决呢````

@monkeydone
Copy link

我写了一个脚本来解决这个问题,仓库是https://github.com/lijunjieone/replugin-resolve-deps-conflict.git ,当遇到冲突的时候,通过脚本删掉冲突的文件.目前测试还算ok

@SkyEric
Copy link
Contributor

SkyEric commented Feb 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants