Build fails in Android Studio after adding library - android

I've been using Android Studio 1.0.2 for a while now and have had no problems. I have a fairly simple app that uses Fragments. Originally I was using the built-in Fragment framework as my target devices will be 4.0.2 upwards. However, due to bugs in the Framework on earlier devices I decided to move to using the Fragment support library (why anyone would not use this over the built-in - well, that's another question...)
I added the library, com.android.support:support-v4:21.0.0, to my build.gradle, thus:
dependencies {
compile 'com.android.support:support-v4:21.0.0'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.amazonaws:aws-android-sdk-core:2.1.5'
compile 'com.amazonaws:aws-android-sdk-s3:2.1.5'
compile 'com.android.support:appcompat-v7:21.0.3'
}
(I already had appcompat-v7 in the list).
All good so far. After converting the fragment manager calls and imports I did a build and got this:
Error:Execution failed for task
':app:prepareComAndroidSupportAppcompatV72103Library'. Failed to
create parent directory
'D:\current-projects\android_studio_projects\WallPaintings\app\build'
when creating directory
'D:\current-projects\android_studio_projects\WallPaintings\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3'
I performed a synchronise and then I did an Invalidate Cache and restart. I then performed another build and got the same result.
Then, after some reading on SO, I discovered you have to perform a "Synch Project with Gradle files". I did this and it worked - compiles up, builds the APK, etc. Fantastic.
However, from that point on, every time I do a Clean or a Rebuild I end up with the same error until I perform the gradle synch.
What is the problem? I can't see what I've done wrong. There is ample disk space and the directory where it attempts to create the things is read/write.
Or is this yet another piece of black-box magic / dark arts that one needs to learn in order to use Android Studio (come back Eclipse - all is forgiven!!)

Well, I restarted Studio numerous times and tried other possible solutions but nothing worked - it stubbornly kept getting the same error so I gave up and just went back to working on my app, resigned to having to do a Synch Gradle after a Clean.
Then yesterday it started no longer reporting the error on a clean.
Black magic.
I was never a great fan of Eclipse, but the more I use Android Studio the more I realise this isn't a 1.0 - it's still very much a Beta.
Closing this question as it has been "solved" - all by itself!

Related

Unsupported kotlin version

My gradle build completes successfully, but I get:
WARNING: Unsupported Kotlin plugin version.
The `embedded-kotlin` and `kotlin-dsl` plugins rely on features of Kotlin `1.5.31` that
might work differently than in the requested version `1.6.10`.
All of my build.gradle.kts scripts refer to using version 1.5.31. The only association my project has with version 1.6.10 is that Android Studio has the Kotlin version 1.6.10 plugin added. If I try to disable that plugin, I get a message that several other plugins will be disabled. If I accept that, android studio crashes and will not start up again. It won't start up again even if you reinstall android studio again. The solution is to find the file named "disabled-plugins.txt" and delete that file. It's in your AppData folder and in a JetBrains subdirectory. It turns out that it's one or more of those other disabled plugins that prevents Android Studio from starting up again.
The question I have is how do I fix this version mismatch issue. I can't delete the plugin from Android Studio for the reasons I mentioned above. If I try to update my project to using version 1.6.10 I get literally 100's of unresolved dependencies. And it seems from opinionated investigation that 1.6.10 still have too many issues for general use.
By the way, when I look at the gradle window for the project I can see where the dependencies come from. Usually when I look at the gradle window I just see sub project folders that I can drill into for more information, but for this project, it has an additional folder name dependencies. I don't know how they get into my project. But when I look at their version numbers that's where the 1.6.10 mismatch happens.
So, I think I understand why the warning message is valid, I'm at a lost on what I need to do to correct this situation. For the moment, I'm just ignoring the warning, and so far I'm not finding any issues in proceeding that way. But that's means I'm proceeding, without an understanding of what's going on here! Sometimes that's okay and at other times that's a bad judgment The error message itself seems inverted. I would think that 1.6.10 is the embedded kotlin and kotlin-dsl since it an android studio plugin, but the error message seems to say it in the opposite way. So anyway, if someone can bring some clarity as to what's going on, and how I'm thinking wrongly about this problem would be greatly appreciated.
I'll accept the following as the answer to what's going on about the unsupported kotlin version:
https://github.com/gradle/gradle/issues/13020
So, for the moment, I'll go on like this is just a nuisance warning and ignore that.
What I just did was to re-create my Android Studio from a blank brand new project. I copied and pasted stuff from the previous project into the new project. I copied the source and build.script.kts files, so essentially everything is a copy of the disabandoned project. This new project didn't give me the WARNING message anymore. And in additional, I'm now able to upgrade my project to using kotlin 1.6.10, which I previously couldn't do because of the literally 100's of dependencies resolution issues. Whatever, that issue went away, and a lot of others things started working as expected once I recreated the project. I can't say what got my project into that weird state. Deleting the .gradle and .idea folders, wouldn't fix the problem. I didn't try deleting the JetBrains cache, I wish I would have tried that.

Gradle issue with sceneform - Program type already present: com.google.ar.schemas.lull

I am working on a project that will have a 3D model viewer in one fragment. In order to do so, I decided to use sceneform.
I downloaded sceneform plugin into Adnroid studio, downloaded and extracted sdk from Github, and I also copied libsceneform_runtime_schemas library into my project. I've added to my sceneform buil.gradle file line
implementation files("../libs/libsceneform_runtime_schemas.jar")
but that results in an error:
Program type already present: com.google.ar.schemas.lull.AabbDef
It is worth noticing that this is the first file in the jar under this path - which probably means that there will be more collisions.
If I'd try not to implement this library, then I get an error:
error: package com.google.ar.schemas.sceneform does not exist
I am using ar:core:1.17.0, and minSdkVersion 24 in sceneform gradle.
I've cleaned and rebuilt the project, Invalidate Caches/Restart, and added multiDexEnabled- although I am not sure if I did it correctly.
By using gradlew sceneform:dependencies I didn't find mentioned file.
I don't know how I can move forward, any help is much appreciated. If I can provide additional information, please let me know.
Edit 1:
I've also tried to work with
implementation files("../libs/libsceneform_runtime_schemas.jar"){
exclude ...
}
But I couldn't make it work. I wonder if that could be my solution.
Also, why does it try to implement this class since it already exists? Shouldn't there be some sort of check for that?
I solved my problem by restoring my project from repo to the last moment before including sceneform, and I proceeded with all of the steps again; Gradle dependencies to the libsceneform_runtime_schemas, min java 8, min SDK version, copying scenformscr and sceneformux to my project again, and lastly - upgrading all classes to AndroidX.
After two days almost I couldn't remove the error, and I don't know what went wrong before, but this time it works like a charm.
TL;DR - I removed the sceneform from my project and imported it again.

Android: Using several version of the same library for different flavors

I'm needing help again with my strange projects ;)
So I'm still building a library, and I need to use libA-1.01.jar and libA-2.1.jar
Of course I don't want them in the same flavor, so I used in my gradle file:
flavorACompile files('libs/libA-1.01.jar')
flavorBCompile files('libs/libA-2.1.jar')
This works fine when compiling with gradlew in command line. But the issue is that my classes don't see both libraries. So when I'm coding I can only import the first one (1.01). So I can't use my IDE to code properly I have to guess emacs style if everything is ok and compile to see...
How can I tell Android Studio that the 2 libraries are present? I tried added them both to compile without flavor (just to force android studio to use them) but it didn't work.
I'm sure there is a simple way to do this, but I can't seem to find it :(

Gradle build VS eclipse build

I have a problem with a build for one specific application with gradle. The application can be compile and build with eclipse and it works well on the tablet. When I try to build it with Gradle I get error in the "compileDebugJava" part. I get this error
"error: cyclic inheritance involving class1
public class class1 implements class2"
I get a bunch of other error after this one but this is the one on the top. My project is depending on another one and this another is depending on a nother one. I just don't know why it works in eclipse but not with Gradle.
I've fixed it. It appears that Eclipse is more permissive than gradle on the build system. There really was a cyclic inheritance in the code that needed to be fixed. I don't know how, but eclipse allow it. After fixing the code, all was fine with a clean build.

How do I import com.google.android.gms.* in Android Studio using a Gradle build?

I have followed the procedure as described here : Setup
I have clicked on the little 'Sync project with Gradle' button. Gradle and Android Studio seem to find everything but then I can't actually use the gms code. If I try to import, I will get autocomplete for com.google.android.gms but no further. I have updated all the packages with Android SDK Manager.
I'm running Android Studio 0.4.2.
My minSdk is set to 9
my build.gradle includes compile 'com.google.android.gms:play-services:4.0.30'
As far as the procedure is concerned I should be ready to code, but it just doesn't work. Any ideas?
[Edit, added info]
I can find the ComGoogleAndroiddGmsPlayServices3265.aar file in my exploded bundles directory. Inside of that file I also find the common directory and inside that I find the GooglePlayServicesUtil.class (which is what's not being found in my app)
I am lost.
[Edit 2]
The problem is not specific to Google Play Services OR Android Studio. I tried adding another library (HoloColorPicker) and had the same results. However, I was able to add the library's resources to my project! I was able to add them in my XML layouts and view them in my application. I was able to interact with them, they worked fine. The problem arose again when I tried to reference them in the code. Exactly like the case with gms, I had code completion when trying to import up to the point of the actual class, and I could not declare the class in the code.
I was able to use the library by cloning it and importing the project.
Also, this is not an Android Studio problem because the same thing happens on the command line with "./gradlew clean build"
This is a current bug in Android Studio: https://code.google.com/p/android/issues/detail?id=64508 to be fixed this week.
The workaround is to close the project, delete the .iml files and .idea project and re-import the project.
Keep Your compile 'com.google.android.gms:play-services:4.0.30' as very first line in build.gradle dependencies like
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:+'
}
`
Open File> Project Structure and do the following steps
Select your main module in which you want to add dependency and click on OK.
Now try to import.
I think the most important question is what you want to achieve. Not all code is under this package. Not even sure which one is.
As noted before, this is a bug with Android Studio. It just don't recognize the path for classes and shows you like if there is an error. If you try compiling you'll see that everything just work fine.
A googler recently said it'll be addressed in this week release, so, be patient and lets see whats coming.
The fact that AS is in Preview mode tell us this sort of things are going to happen :)
Android studio is crazy one, I think.
It's removed "Import module" function and you can do "New module" only.
If you are developed on Eclipse, you need export all your projects to Gradle before switch to Androids studio (WTF?)
I prefer "IntelliJ IDEA Community Edition", although It's similar Android studio but it's better than Android studio (at least until now). You just import your project as eclipse format, IntelliJ IDEA will detect dependences libraries automatic (May be you need import jar libraries by hand) and rebuild project. That Done.

Categories

Resources