Android Studio 3.0 Canary 1: Gradle Sync Error - android

I'm getting this error in my Kotlin project:
Here is my app's Gradle files:
I haven't really done anything to the project yet except add Kotlin and Anko dependencies. Not sure what's happening...

This is a well known issue with Anko. It is mentioned here.
You can try to exclude implicit com.google.android:android dependency from Anko's dependencies:
compile("org.jetbrains.anko:anko-appcompat-v7:$anko_version") {
exclude group: 'com.google.android', module: 'android'
}
(Keep in mind as you are using separate Anko libraries - you may need to use exclusion in multiple pleces).
You can also try to update Gradle plugin:
classpath 'com.android.tools.build:gradle:3.0.0-alpha2'

Add the dependency inside you app-level app module :
// Anko
compile 'org.jetbrains.anko:anko-sdk15:0.8.2' // sdk19, sdk21, sdk23 are also available
compile 'org.jetbrains.anko:anko-support-v4:0.8.2' // In case you need support-v4 bindings
compile 'org.jetbrains.anko:anko-appcompat-v7:0.8.2' // For appcompat-v7 bindings

As In your screenshot I can see that while adding Anko dependencies you didn't mention the Anko version , kindly mention that it should work fine post that.

Add like this too.
flavorDimensions "default"
productFlavors {
debug {
dimension "default"
...
}
release {
dimension "default"
...
}
foss {
dimension "default"
...
}
}

AFAIK, its Google Repository which is missing. As you can see the ide itself is informing you about it.
Failed to resolve: com.google.android:android.2.3.1 which is Google Repository.
If you are connected to internet then simply click on Install Repository and Sync project in the Gradle Sync window. It will download the google repository and sync your project.

Related

Replacing a gradle dependency in Flutter library

I'm writing a Flutter app that uses the "flutter_reactive_ble" plugin. That plugin, in turn, uses "RxAndroidBle" java library. I have made a small change to RxAndroidBle, and it compiles into .aar files. But my Gradle-fu is insufficient to figure out how to tell flutter_reactive_ble to use my version instead of retrieving the latest version from the web. I'd be happiest if I could just point to my local .aar files, but if I have to serve them from my own site, that would be OK as well.
After building my app, the "android/app/build.gradle" file ends with:
dependencies {
. . .
implementation "com.polidea.rxandroidble2:rxandroidble:1.11.1"
}
I assume that's what I'll need to change, but nothing I can find in the Gradle docs look like what I need.
I think, you need fork repo first
And .yaml set like this
(read this)
I think you can do something like this in gradle:
configurations.each {
c -> c.resolutionStrategy.dependencySubstitution {
all { DependencySubstitution dependency ->
if (dependency.requested.group == 'com.polidea') {
dependency.useTarget '<your grade plugin>'
}
}
}
}
It can be replaced alike this:
configurations.all {
exclude group: 'com.polidea.rxandroidble2', module: 'rxandroidble'
}
dependencies {
implementation files('libs/rxandroidble.aar')
// or depend on the module.
}
If you want your app to use your aar, then just declare it as dependency. Or you want the flutter_reactive_ble to use it? I don't think it's possible. You'd have to make pr to RxAndroidBle and then pr to flutter_reactive_ble to take that version in.
I think overriding android dependency may solve your problem.
in build.gradle file of android project
configurations.all {
resolutionStrategy {
force ‘<android library with specific version>’
}
}
in your case:
force com.polidea.rxandroidble2:rxandroidble:1.11.1
check this link for more detail.
--------------------
for adding dependency of local project
in your settings.gradle file add mapping of your local project and include it
project(':local_project_name').projectDir = new File(settingsDir, '<relative path of project>')
include ':local_project_name'
And then add a resolutionStrategy in your project's build.gradle file
configurations.all {
resolutionStrategy {
force implementation project(':local_project_name')
}
}
You need to fork flutter_reactive_ble, go to build.gradle and remove this line then open android studio and open File > Project Structure > Dependencies:
Then Add your module library(.aar files you built):
in the end, android studio will add this line to build.gradle:
implementation(project(path: ":example-library"))
Make sure to use flutter_reactive_ble from your git repository inside your app, in your .yaml file add:
flutter_reactive_ble:
git:
url: your/git/flutter_reactive_ble/repository/url
ref: tag or commit id

Error: Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat

After upgrading to Android Studio 3.1, I started to get following error during build. Project uses multidex and DX is enabled by default as you would notice in the error. I tried to check dependency graph to understand what is going on but so far have no clue. Interestingly this only fails on my machine. I cleaned up everything, including reinstall etc but nothing worked.
Anyone had the same issue and how did you solve it? Or any direction that I can take a look?
AGPBI: {
"kind":"error",
"text":"Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat",
"sources":[{}],
"tool":"D8"
}
This is the task that fails:
transformDexArchiveWithExternalLibsDexMergerForDebug
I checked similar issues and it seems random things fixes their problem, I'm not sure what is the real cause.
For my solution (I do not know it will work for you):
Firstly I followed #Orhan Obut's solution:
Search for duplicate classes in your project
I found that there are more than one class files in different libraries.
Then I put the ignore annotation above my support dependency in my project module's build.gradle (app folder):
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
I realized that ignorance is no solution, because the error did not go away, even after clean-rebuilding and clearing/invalidating cache for the project.
See: Infographic: 11 Most Common Android Errors and How to Fix Them
So I explored more, and found out this link:
Android - Understanding and dominating gradle dependencies
It suggests ways to resolve conflicts. Hence I put this on my gradle just above the declarations of dependencies:
configurations.all {exclude group: 'com.android.support', module: 'support-v4'}
Since then when I search for duplicate classes for this one using #Orhan Obut's solution above, I find only single entry in the result. That meant that there were no duplicates.
Also, it will be better if you migrate to AndroidX with latest SDK and build tools. Make sure you don't have older support dependencies anywhere.
Happy Coding :-)
I have my solution by change this:
implementation 'com.android.support:appcompat-v7:27.0.0'
to
implementation 'com.android.support:appcompat-v7:26.0.0'
it works for me.
I managed to determine the root cause by using the following steps. It may be different use case for each issue, therefore this is the way to determine the root cause.
Go to android studio
Navigate -> Class
Check include non-project classes
Copy paste full class path with package name. android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat
You should be able to see where it is used. Most probably you may need to remove it from one of them.
In my case the issue was ViewPagerIndicator library was downloading support library as jar. Removing it solved the issue.
For the easy option just add
configurations.all {exclude group: 'com.android.support', module: 'support-v4'}
before dependencies in build.gradle app module, it should ignore v4 support libraries, and the duplicate error will go away.
Adding the below line in the build.gradle of the app level worked for me
implementation 'com.android.support:support-v4:28.0.0'
As for me this helps to resolve such issues
all support libraries (also included thirdy-part) reduces to specified version
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '28.0.0-beta01'
}
}
}
}
I also faced the same problem just a while ago. In my case the third party library used the older AccessibilityServiceInfoCompat version v4 22 and i already updated to newer one v4 28 so both support library classes clashed
In y case I've resolved issue by
implementation 'com.android.support:appcompat-v7:26.0.0'
to
implementation 'com.android.support:appcompat-v7:27.1.1'
some third-party library may be use different version of support library. you can use ./gradlew :app:dependencies find out it, and then import the current version of the support library.
I have my solution by change this :
android / build.gradle
buildscript {
ext {
supportLibVersion = "27.0.3"
}
}
to
buildscript {
ext {
supportLibVersion = "26.0.0"
}
}
directory android / app / build.gradle
defaultConfig {
multiDexEnabled true
}

android Canary 3.0 beta 5 unknown element <library> found

I'm trying to add mopub. But when I do, the build manifest adds a library tag and then says it doesn't know what it is. If I remove the link, all works fine.
compile('com.mopub:mopub-sdk:4.16.0#aar') {
transitive = true
}
<library android:name="moat-mobile-app-kit" />
Error:(34) unknown element found
Error:E:\Web\Studio\Opus\app\build\intermediates\manifests\full\live\debug\AndroidManifest.xml:34
unknown element found
Error:java.util.concurrent.ExecutionException:
com.android.builder.internal.aapt.AaptException: AAPT2 link failed:
Error:com.android.builder.internal.aapt.AaptException: AAPT2 link
failed: Error:Execution failed for task
':app:processLiveDebugResources'.
Failed to execute aapt
I experience this issue, after several inspections i can only conclude that manifest merger, includes the line
<library android:name="moat-mobile-app-kit" />
from mopub avid and moat kit,as this is not supported in the new android gradle plugin, your best bet for now will be to disable viewability measurement by editing mopub dependency line as defined below
compile('com.mopub:mopub-sdk:4.17.0#aar') {
transitive = true
exclude module: 'libAvid-mopub' // To exclude AVID
exclude module: 'moat-mobile-app-kit' // To exclude Moat
}
The only solution I have found so far is to use MoPub 4.15.
Edit: MoPub has confirmed the issue and they wouldn't give me an ETA on a fix.
Edit: 4.18 still broken.
Edit: I should mention I am using 4.19 now with Moat still disabled and using the code to remove Moat, but I also have to do that on other ad networks that include Moat as well. So if you are having this issue you might want to look at all your ad network compile lines.
Edit: According to MoPub, this is fixed on 4.20.0 and it seems to work for me.
There is a moat update that seemingly solves the problem. For me this compiles properly:
implementation 'com.mopub:mopub-sdk:4.19.0#aar'
implementation 'com.moat.analytics.mobile.mpub:moat-mobile-app-kit:2.4.1'
I got a response from Mopub.
Android Studio 3 uses Gradle 4, and Gradle 4 deprecates the use of the "compile" statement. Therefore you will need to use keywords such as "api" or "implementation" in place of "compile". Please also reference this StackFlow link for additional information.
link here
Add this to your gradle dependencies.
exclude module: 'moat-mobile-app-kit' if you are using Mopub SDK <= 4.18.0.
It worked for me.
If you are using 4.20.0, they fixed this issue.
https://developers.mopub.com/docs/android/changelog/#version-4200-february-20-2018
keep repositories and dependencies at a file(build.gradle) ,not two file, like repositories at root build file ,dependencies at module build file
repositories {
// ... other project repositories
jcenter() // includes the MoPub SDK and AVID library
maven { url "https://s3.amazonaws.com/moat-sdk-builds" }
}
// ...
dependencies {
// ... other project dependencies
compile('com.mopub:mopub-sdk:4.16.0#aar') {
transitive = true
}
}

How can I find the dependencies in my app that are using findbugs? (findbugs conflict)

I'm trying to discover the specific conflict when adding espresso to my app's gradle file:
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') {
exclude group: 'com.android.support', module: 'support-annotations'
}
Android Studio states "Warning:Conflict with dependency 'com.google.code.findbugs:jsr305'.
Dependency conflict error in my Android app which has Android Tests states the error means the dependency I am using in my app is version 3.0.0 while the one in my test app is 2.0.1.
However, my gradle never explicitly adds "com.google.code.findbugs", indicating it was part of another dependency I added to my "compile" and "androidTestCompile" statements. How do I find the dependencies in my app that are using findbugs?
Check your dependencies:
HelloApp/
app/
- build.gradle // local gradle config (for app only)
...
- build.gradle // global gradle config (for whole project)
- settings.gradle
- gradle.properties
Check here:
dependencies {
compile project(':libraries:lib')
}
Later check this LINK you have Unit testing support orientation
Execute the following command:
./gradlew app:dependencies
This will print a (large) graph of dependencies.
For the meaning of the arrows and stars, please refer to this SO answer.

"already added" exception with ormlite and gradle

I'm using android studio 0.2.3 with gradle 0.5 and added the ormlite dependency to the build.gradle file as follows:
compile 'com.j256.ormlite:ormlite-android:4.9'
Gradle downloaded two jar files: ormlite-android.jar and ormlite-core.jar. The problem is, that the jar files contain identically named classes. So I get the following well known exception:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/j256/ormlite/dao/BaseDaoImpl$1;
Some other solution for the same problem with maven exists, suggesting to exclude the ormlite-core.jar. This should work if all classes from ormlite-core.jar are included in ormlite-android.jar - I didn't check this btw. In that case, I don't understand why the ormlite-core is in this ormlite android dependency package... I'm explicitly adding ormlite-android, as you can see in the snippet above.
But how to exclude the ormlite-core.jar in gradle. Everything I found was for gradle 1.6, but android studio uses gradle 0.5 - or is this just the version of the android gradle wrapper?
.:EDIT:.
To make the dependencies clearer, I add my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.google.android.gms:play-services:3.1.+'
compile 'com.j256.ormlite:ormlite-android:4.9'
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
}
Why I think there are same classes in the two ormlite libs? ==> See the screenshot.
Aren't the opened packages identical? Even the source is. The only distinct classes I found were SqliteAndroidDatabaseType and those in the com.j256.ormlite.android package.
The ormlite-android jar you're using is definitely wrong. My guess is that someone built it incorrectly with ormlite-core exported, which is why you're getting the merge conflicts. If you look at the source for ormlite-android, it isn't supposed to have most of those packages/classes included.
I'm not sure how the ormlite-android versioning works, but it looks like 4.46 is the actual latest version (updated 29-Jul-2013), not 4.9 (updated 26-Jan-2011). I'd recommend using 4.46 instead (that's what works for me) with:
'com.j256.ormlite:ormlite-android:4.46'
Thanks to #cproinger for the answer in another related question.
WOW, now it works! I misunderstood the versioning (my fault). But anyway, the newer version (4.46) contains only the android specific classes in the ormlite-android.jar and everything else in the ormlite-core.jar. Great, thanks #cproinger!

Categories

Resources