Log4j configure for Android using gradle - android

I want to use log4j to write logs to sdcard. How to configure log4j specifically using gradle ?
Many threads I have seen ask to download and add jar as library, I can't find a good post on configuring log4j using gradle.

This post describes the solution using using the android-logging-log4j.jar.
Gradle dependencies for the same:
Original code
compile group: 'de.mindpipe.android', name: 'android-logging-log4j', version: '1.0.3'
compile group: 'log4j', name: 'log4j', version: '1.2.17'
Updated : Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
implementation 'de.mindpipe.android:android-logging-log4j:1.0.3'
implementation 'log4j:log4j:1.2.17'

Related

Exclude duplicate classes from 2 local .aar files in libs folder

Can we remove duplicate classes from the local .aar files in libs folder.
Duplicate class com.regina.first.core.C$RefreshWebClientQueryIds found in modules jetified-regina-runtime.jar (abc.aar) and jetified-gms-sdk-debug-runtime.jar (xyz.aar)
I have tried using-
implementation (files('libs/abc.aar')) {
exclude 'com.regina.first.core.C'
}
implementation fileTree(dir: 'libs', include: ['xyz.aar'])
But got the following response from the gradle although i am already using gradle version 4.0.1 -
Gradle DSL method not found: 'exclude()'
Possible causes:
The project 'atv-retail-app' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 4.0.1 and sync project
The project 'atv-retail-app' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file
The build file may be missing a Gradle plugin.
Apply Gradle plugin
Based on the official Gradle documentation in order to exclude a package/group from the dependency you should use the syntax below
dependencies {
implementation('commons-beanutils:commons-beanutils:1.9.4') {
exclude group: 'commons-collections', module: 'commons-collections'
}
}

Error in Android Studio Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api' [duplicate]

I just update my android studio to 3.0 now, but when I try to build apk on my project, it's shows following error:
Project depends on com.google.android.support:wearable:2.0.0, so it must also depend (as a provided dependency) on com.google.android.wearable:wearable:2.0.0
My build.gradle is like that:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':lpd')
compile 'com.google.android.support:wearable:2.0.0-alpha2'
compile 'com.google.android.gms:play-services-wearable:9.4.0'
compile files('libs/zxing_2.3.0.jar')
compile(name: 'hwwearableservice-release', ext: 'aar')
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
}
Anything wrong with it?
As per the new gradle dependency instruction the compile has been deprecated so for libraries use api and use the latest stable lib version as 2.1.0
and since the version is a stable release so
api 'com.google.android.support:wearable:2.1.0'
or it's better to use
implementation 'com.google.android.support:wearable:2.1.0'
implementation
if an implementation dependency changes its API, Gradle recompiles
only that dependency and the modules that directly depend on it. Most
app and test modules should use this configuration.
api
When a module includes an api dependency, it's letting Gradle know
that the module wants to transitively export that dependency to other
modules, so that it's available to them at both runtime and compile
time. This configuration behaves just like compile (which is now
deprecated), and you should typically use this only in library
modules. That's because, if an api dependency changes its external
API, Gradle recompiles all modules that have access to that dependency
at compile time

Migrating to Gradle 3.0.0: Error - D8: Program type already present

I am migrating my Android project to Gradle 4.4 and Android Gradle plugin 3.1.2.
It has a library module which depends on parceler library and defines its dependency as follows:
build.gradle of library module:
...
// parceler for serialization (https://github.com/johncarl81/parceler)
implementation "org.parceler:parceler-api:1.0.4"
annotationProcessor "org.parceler:parceler:1.0.4"
...
This seems to compile well and generates my aar file.
Further, my main app module also has a direct dependency on parceler module and contains above lines as dependencies in its build.gradle, along with above aar file.
build.gradle of main app module:
...
api(group: 'com.example.mylibrary', name: 'mylibrary', version: "1.0.7", ext: 'aar') {
transitive = true;
changing = true
}
// parceler for serialization (https://github.com/johncarl81/parceler)
implementation "org.parceler:parceler-api:1.0.4"
annotationProcessor "org.parceler:parceler:1.0.4"
...
Everything works until I try to generate my APK, which fails with the following error.
D8: Program type already present: org.parceler.Parceler$$Parcels$1
Task :MPCApp:transformDexArchiveWithDexMergerForRelease FAILED
When I expand my library project in Android studio, I see Parcels.class under org.parceler package. But it seems similar file is also generated by main app module under the same package which is causing the clash.
Upgrade to the latest (currently 1.1.10) - We got rid of the Parcels generated class.

Conflict with dependency findbugs when importing Google Cloud PubSub in Android gradle

I have a bare empty Android project, I am following this guide for PubSub java client.
So basically I am only adding:
compile group: 'com.google.cloud', name: 'google-cloud-pubsub', version: '0.11.0-alpha'
to my gradle (the complete file is here)
The error I get is:
Error:Conflict with dependency 'com.google.code.findbugs:jsr305' in project ':app'. Resolved versions for app (3.0.0) and test app (2.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
There are also 2 warnings:
Warning:WARNING: Dependency org.json:json:20151123 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for release as it may be conflicting with the internal version provided by Android.
I think this is related to #1319 but I can't make those suggested solutions work out.
Any suggestions?
It seems that excluding those replicated dependencies may fix it:
so, instead of
compile group: 'com.google.cloud', name: 'google-cloud-pubsub', version: '0.11.0-alpha'
this would produce no errors nor warnings:
compile ('com.google.cloud:google-cloud-pubsub:0.11.0-alpha') {
exclude group: 'com.google.code.findbugs'
exclude group: 'org.apache.httpcomponents'
exclude group: 'org.json'
}

what is the difference between compile, testCompile and provided in gradle dependency

I am using android studio and in project structure -> dependencies tab following options i can see:
Compile
Provided
APK
Test Compile
Debug Compile
Release Compile
my question: what is the difference between compile, testCompile and provided in gradle dependency
compile is the group of dependencies you need to build your application while testCompile is a group of dependencies that you need only for testing.
Look for instance at this build.gradle (taken from here)
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
This specifies that hibernate-core is needed to build your code but junit (a testing framework) is needed just for testing. Since it's not needed at runtime, it's not going to be included in the released package.
You should read the User Guide that comes with the distribution, or read it online at http://gradle.org/documentation/ .
In short, "compile" is for dependencies for your "main" code, "testCompile" for your test classes, and "provided" is used for dependencies that are used at compile time, but not stored in your WAR file (because they're expected to be available in your web container).
The following posting might have relevant information: Compile, Provided, APK - Android dependency scope .

Categories

Resources