PeriodicWorkRequest with compileSdkVersion 21 - android

I am trying to add PeriodicWorkRequest on an old project. That uses compileSdkVersion 21. I can not update compileSDKVersion.
This is my build.gradle
implementation 'com.android.support:support-v4:21.0.3'
implementation ('com.google.firebase:firebase-messaging:9.8.0')
//{
//exclude group: "com.android.support", module: "support-v4"
//}
implementation ('android.arch.work:work-runtime:1.0.1')
{
exclude group: "com.android.support", module: "support-compat"
exclude group: "com.android.support", module: "support-core-ui"
exclude group: "com.android.support", module: "support-fragment"
exclude group: "com.android.support", module: "support-core-utils"
}
I get these errors:
Android resource linking failed
build\intermediates\packaged_manifests\debug\AndroidManifest.xml:408: AAPT: error: attribute android:directBootAware not found.
Is it possible to include WorkManager in my project?
Thanks

Related

Multiple dex files define Lorg/apache/commons/logging/impl/LogFactoryImpl

As the title says, Multiple dex files are being defined, I'ven been digging around with no luck on how to solve this one, so I decided to reach out on the community, to make the story short, I'm updating the gradle build system of this legacy project from gradle 0+ to gradle 3+, I managed to refactor the common configurations such as flavoring, dependencies (from compile to api/implementation), (you name it..), until I stumbled on this dex issue, the first thing that came to my mind is to break down the dependencies by the help of Using gradle to find dependency tree, but unfortunately its taking my time too much on gradlew commands and still ending up with gradlew issues(unable to execute AndroidSdk something), so I took a step back(to minimize the time I needed) and did this... (playing the odds)
dependencies {
api (project(':<omitted project name>')) {
exclude group: 'org.apache.commons', module: 'logging'
}
api (project(':<omitted project name>')) {
exclude group: 'org.apache.commons', module: 'logging'
}
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:design:23.1.0'
implementation ('com.google.code.gson:gson:2.3'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.squareup.picasso:picasso:2.5.2'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.squareup.okhttp:okhttp:2.4.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('org.bitbucket.b_c:jose4j:0.5.2'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'commons-io',name:'commons-io',version: '2.0.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'com.jcraft', name: 'jsch', version: '0.1.44-1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.android.support:design:23.1.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.android.support:appcompat-v7:24.2.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.facebook.android:facebook-android-sdk:4.10.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-gcm:9.0.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-auth:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.github.PhilJay:MPAndroidChart:v3.0.2'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'org.apache.commons', name: 'commons-compress', version: '1.3') {
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'org.apache.commons', name: 'commons-vfs2', version: '2.2') {
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('io.socket:socket.io-client:1.0.0') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
exclude group: 'org.apache.commons', module: 'logging'
}
api fileTree(dir: 'libs', include: ['*.jar'])
api files('libs/nfc7003.jar')
api files('libs/minilcd7003.jar')
api files('libs/Scan7003.jar')
api files('libs/UserInterface.jar')
api files('libs/printer7003.jar')
}
I cant figure out whos dependency in the above list has this transitive issue with the logging framework, I define an exclusion on them all, still no luck..
just to mention the reason behind : I need the advance profiling of Android studio 3, and the latest gradle(4+)/build tool(3+) must be used to be able to do so, that lead me here ..
please help me on this one, thanks in advance...
[Edit] Build message:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define
Lorg/apache/commons/logging/impl/LogFactoryImpl$2;
Error:com.android.dex.DexException: Multiple dex files define
Lorg/apache/commons/logging/impl/LogFactoryImpl$2;
Error: at
com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error: at
com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error: at
com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error: at
com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error: at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error: at
com.android.builder.dexing.
DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error: at
com.android.builder.dexing.
DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error: at java.util.concurrent.
ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error: at
java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error: at
java.util.concurrent.
ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error: at
java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error: at
java.util.concurrent.
ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task '
:<omitted project name>:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException:
com.android.dex.DexException: Multiple dex files define
Lorg/apache/commons/logging/impl/LogFactoryImpl$2;
The problem is because you are using duplicated library in your build.gradle.
First, for support library, you need to use the same version. Do not use the following:
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:design:23.1.0'
implementation ('com.android.support:design:23.1.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.android.support:appcompat-v7:24.2.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
instead use the following:
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:design:25.4.0'
// appcompat is implicitly include within support design.
Second, for google play service, use the same version. Do not use the following:
implementation ('com.google.android.gms:play-services:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-gcm:9.0.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-auth:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
instead use:
// Dont use the whole play service library
//implementation 'com.google.android.gms:play-services:9.8.0'
implementation 'com.google.android.gms:play-services-gcm:9.8.0'
implementation 'com.google.android.gms:play-services-auth:9.8.0'
Third, to exclude common-logging you need to use something like this:
compile(group: 'org.apache.commons', name: 'commons-compress', version: '1.3'){
exclude group: 'commons-logging', module: 'commons-logging'
}
or use the following:
configurations.all {
exclude group: "commons-logging", module: "commons-logging"
}
You don't need to adding exclude to every library because some library didn't have any commons-logging inside them.
try
// https://mvnrepository.com/artifact/commons-io/commons-io
compile group: 'commons-io', name: 'commons-io', version: '2.6'
remove all exclude options and commons-io.
above dependency might just work fine

android:facebook-login:4.29.0, exclude android.support to use it with SDK 26

I am using SDK 26 (support 26.1.0). I have read https://stackoverflow.com/a/47360826/455796 and did the following,
def support_version = '26.1.0'
implementation "com.android.support:support-v4:${support_version}"
implementation "com.android.support:appcompat-v7:${support_version}"
implementation "com.android.support:support-core-utils:${support_version}"
implementation "com.android.support:customtabs:${support_version}"
implementation "com.android.support:design:${support_version}"
implementation "com.android.support:cardview-v7:${support_version}"
implementation "com.android.support:support-annotations:${support_version}"
implementation "com.android.support:support-core-utils:${support_version}"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.facebook.android:facebook-login:4.29.0'{
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'cardview-v7'
exclude group: 'com.android.support', module: 'customtabs'
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'support-core-utils'
}
but it caused,
Error: Could not find method com.facebook.android:facebook-login:4.29.0() for arguments [build_b8xyg6u02oo8u0yoih8oe3tvs$_run_closure2$_closure6#b26df6f] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Can I solve this, or would I have to use an old version of the Facebook SDK?
Use:
implementation ('com.facebook.android:facebook-login:4.29.0') {
exclude group: 'com.android.support', module: 'support-v4'
//others
}
or
implementation 'com.facebook.android:facebook-login:4.29.0', {
exclude group: 'com.android.support', module: 'support-v4'
//others
}

Error:Conflict with dependency 'com.android.support: when update from 23.1.1 to 23.4.0

I have upgrade my build.gradle from
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
to
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
However, the existence of below test libraries cause some gradle sync error
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'support-annotations'
exclude module: 'recyclerview-v7'
}
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2')
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2'
The error is
Error:Conflict with dependency 'com.android.support:appcompat-v7'. Resolved versions for app (23.4.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
Error:Conflict with dependency 'com.android.support:design'. Resolved versions for app (23.4.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
Error:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.4.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
How could I resolve this conflicts? Should I upgrade my test libraries as well (how to know which version to upgrade to)?
I perform various exclusion to resolve the problem. I hope there's a better answer (e.g. upgrade the test library?).
androidTestCompile ('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test:rules:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'design'
exclude module: 'support-annotations'
exclude module: 'recyclerview-v7'
}
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test.espresso:espresso-web:2.2.2') {
exclude group: 'com.android.support', module: 'support-annotations'
}

app:transformClassesWithJarMergingForDebug FAILED

when I try to run the app I am getting this error
before
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzsk.class
Now
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzqz$zza.class
I referred this,this and this. Tried the solutions mentioned there. Still I am far away from solving the Issue.
Please have a look on the app build gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile('com.android.support:appcompat-v7:23.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.android.support:recyclerview-v7:23.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.android.support:cardview-v7:23.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.android.support:design:23.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'com.clevertap.android:clevertap-android-sdk:2.0.11'
compile 'com.android.support:support-v4:23.1.1'
compile('com.google.android.gms:play-services-analytics:8.3.0')
{
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.google.guava'
}
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile "com.squareup.picasso:picasso:2.4.0"
compile('com.google.android.gms:play-services-gcm:8.3.0') {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.google.guava'
}
compile('com.google.android.gms:play-services:8.3.0') {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.google.guava'
}
compile 'de.hdodenhof:circleimageview:1.3.0'
compile project(':volley')
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
compile 'com.android.support:multidex:'
apply plugin: 'com.google.gms.google-services'
}
I am happy to provide more information if needed.
UPDATE
When I comment compile 'com.clevertap.android:clevertap-android-sdk:2.0.11' It is working fine.
please check if some of your dependencies have multidex as dependency and exclude it. For example for Facebook SDK: you have this
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
change to this
compile('com.facebook.android:facebook-android-sdk:4.7.0') {
exclude group: 'com.android.support', module: 'multidex'
}
and check for other also.
Solved the issue by updating the com.google.android.gms:play-services version
from 8.3.0 to 8.4.0

How to exclude a specific package from the library jar in Android Studio?

I am facing an error of duplicate entry between smack and quickblox libraries. After excluding some groups and modules, I can add two libraries, but I failed to add a third one because of this error:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/jivesoftware/smack/android/AndroidSmackInitializer.class
I have tried a lot of ways to fix this by packaging options and others but none of them didn't helped please help me to try to fix this.
My build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.messenger.Bolo"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java {
exclude 'org/jivesoftware/smack/android/AndroidSmackInitializer.class'
exclude '**/AndroidSmackInitializer.class'
}
}
androidTest {
java {
exclude '**/AndroidSmackInitializer.class'
exclude 'org/jivesoftware/smack/android/AndroidSmackInitializer.class'
}
}
}
packagingOptions
{
exclude 'BuildConfig.class'
exclude 'ExtensionsInitializer.class'
exclude 'AbstractXMPPConnection$8.class'
exclude 'MiniDnsResolver.class'
exclude 'XMPPTCPConnection$PacketWriter.class'
exclude 'ExtensionsInitializer.class'
exclude 'AndroidSmackInitializer.class'
exclude 'XmppStringPrepUtil.class'
exclude 'org.jivesoftware.smack.android.AndroidSmackInitializer.class'
exclude 'org/jivesoftware/smack/android/AndroidSmackInitializer.class'
exclude '**/AndroidSmackInitializer.class'
}
configurations {
all*.exclude group: 'org.jivesoftware.smack.android.AndroidSmackInitializer.class'
}
//useLibrary 'org.apache.http.legacy'
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:design:23.1.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:support-v4:23.1.1'
compile 'org.igniterealtime.smack:smack-im:4.1.5'
compile 'org.igniterealtime.smack:smack-tcp:4.1.5'
compile 'org.igniterealtime.smack:smack-android-extensions:4.1.5'
compile 'org.igniterealtime.smack:smack-extensions:4.1.5'
compile 'org.igniterealtime.smack:smack-core:4.1.5'
compile 'org.igniterealtime.smack:smack-resolver-dnsjava:4.1.5'
compile("com.quickblox:quickblox-android-sdk-core:$rootProject.qbSdkVersion#aar") {
exclude module: 'org.igniterealtime.smack:smack-resolver-dnsjava:4.1.6'
exclude module: 'org.igniterealtime.smack:smack-im:4.1.6'
exclude module: 'org.igniterealtime.smack:smack-tcp:4.1.6'
exclude module: 'org.igniterealtime.smack:smack-android-extensions:4.1.6'
exclude module: 'org.igniterealtime.smack:smack-extensions:4.1.6'
exclude module: 'org.igniterealtime.smack:smack-core:4.1.6'
exclude group: "org/jivesoftware/smack/android/**"
exclude group: "org/jivesoftware/smack/android/AndroidSmackInitializer.class"
exclude group: "org/jivesoftware/smack/android/**"
exclude group: '**/AndroidSmackInitializer.class'
}
compile("com.quickblox:quickblox-android-sdk-chat:$rootProject.qbSdkVersion#aar") {
transitive = true
exclude module: 'org.igniterealtime.smack:smack-resolver-dnsjava:4.1.5'
exclude module: 'org.igniterealtime.smack:smack-im:4.1.5'
exclude module: 'org.igniterealtime.smack:smack-tcp:4.1.5'
exclude module: 'org.igniterealtime.smack:smack-android-extensions:4.1.5'
exclude module: 'org.igniterealtime.smack:smack-extensions:4.1.5'
exclude module: 'org.igniterealtime.smack:smack-core:4.1.5'
exclude group: '**/AndroidSmackInitializer.class'
//exclude module: 'org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.class'
exclude group: "org/jivesoftware/smack/android/AndroidSmackInitializer.class"
exclude group: "org/jivesoftware/smack/android/**"
}
compile("com.quickblox:quickblox-android-sdk-videochat-webrtc:$rootProject.qbSdkVersion#aar") {
//exclude module: 'support-v4'
exclude module: 'org.igniterealtime.smack:smack-resolver-dnsjava:4.1.5'
exclude module: 'org.igniterealtime.smack:smack-im:4.1.5'
exclude module: 'org.igniterealtime.smack:smack-tcp:4.1.5'
exclude module: 'org.igniterealtime.smack:smack-android-extensions:4.1.5'
exclude module: 'org.igniterealtime.smack:smack-extensions:4.1.5'
exclude module: 'org.igniterealtime.smack:smack-core:4.1.5'
exclude group: "org/jivesoftware/smack/android/**"
exclude group: "org/jivesoftware/smack/android/AndroidSmackInitializer.class"
exclude group: "org/jivesoftware/smack/android/**"
exclude group: '**/AndroidSmackInitializer.class'
}
compile files('libs/org.apache.http.legacy.jar')
}
task androidReleaseJar(type: Jar, dependsOn: assembleRelease) {
from "$buildDir/intermediates/classes/release/"
exclude 'org/jivesoftware/smack/android/AndroidSmackInitializer.class'
}

Categories

Resources