Android Studio doesn't compile changes until second compile with Kotlin - android

When I am compiling with Kotlin's puglin, I always have to run the project twice if I make a change, Android Studio does not recognize the change until it runs the project twice, Insnat Run its off and this continues happening

If you use kotlin and retrolambda this might fix it:
me.tatarka:gradle-retrolambda:3.4.0
https://stackoverflow.com/a/41076056/7861527

If you're not using the latest Kotlin plug-in version (1.1.2-5 as of now) and/or Android Studio's latest stable version (2.3.3 as of now), then disabling Android Studio's Instant Run feature may not be able to fix this problem even though it's one of the most common solutions (based on blogs, SO posts here, and etc.) for properly running configuration changes to an app. Android Studio, particularly its alpha/beta versions (Alpha 4 as of now), are obviously bound to have buggy features, and the configuration-change bug could be one of them.

Related

Easiest way to code/debug in Android studio without Gradle

So a couple of days ago, I decided to start android programming using Android studio. After installing the IDE I had some problems syncing Gradle (discussed here). Now I'm trying to use Android studio without Gradle. I've read some topics about using Ant etc. but I don't know which one is the easiest way to do that, And most of them weren't talking about Android studio.(note that I want to use Android studio and build/debug apps normally, just like someone who uses Gradle)
Gradle is the build system for Android. Android Studio uses it for all its builds. You can't build without using Gradle. There were alternative build systems years ago, but they stopped being supported almost a decade ago now. While it would be technically possible to build without gradle, you'd be doing months of work to get a basic build up and running because you'd have to rewrite EVERYTHING google's build does using the alternative system.
Basically you can spend a few days figuring out how to fix your gradle setup (which will almost certainly end up being trivial) or you can spend the next year writing a build system. Pick the first option.

Android Studio shows type mismatch error for compilable kotlin code

In our team, there are two groups of members.
For the first group, Android Studio offers to simplify the code like below and transform redundant declaration of types to lambdas.
For the second group, Android Studio marks the simplified code as incorrect with a type mismatch compilation error. But the code still compilable.
But no one knows what settings to tweak for the second group to join the first group.
Does anyone know, what settings are responsible for this behavior?
Updating Studio to the most recent version (currently 4.1.2) caused Studio to offer to update Kotlin-plugin to 1.4.30 version, which, I believe, solved the problem.
If I'm not mistaking, there was no option to update Kotlin-plugin to 1.4.30 in Android Studio 4.0.2, at least Studio didn't offer to do so and there was no Install-button in Configure Kotlin Plugin Updates settings section.
But I intentionally used a bit outdated version, because AndroidStudio 4.1.2 is buggy as hell.
UPD
Because recent Android Studio has a huge bunch of bugs like this or this making it almost impossible to use, there is no option for me to stay on 4.1.2 until these bugs are fixed.
So I downgraded studio to 4.0.2 again, but installed Kotlin plugin of 1.4.21 version manually. You can do so by downloading it from official JetBrains site and following the screenshot instruction below.
So now I have stable Android Studio and recent Kotlin-plugin which solves type-mismatch problem.

Program type already present: android.support.annotation.AnimRes

This problem happened to me after i updated to the latest version of Xamarin.Forms (4.6.0)
I get this error whenever i try to build my Android Projects in Visual Studio For Mac (8.5.4)
What i tried so far:
Using different versions of the Android Support libraries
Cleaning my NuGet Cache
Reinstalling the SDK
Cleaning, Rebuilding, Restarting VS (several times)
Oddly i managed to get it working for a few builds after changing my support library versions from 28.0.0.3 to 28.0.0.1 manually in the csproj file. However i tried this several times and it doesn't solve the problem.
The problem occurs if i create a fresh Xamarin.Forms project aswell.
Any advice appreciated, as this is starting to be frustrating.
I don't know if this will help, but you should migrate to AndroidX as soon as possible, nevertheless. Xamarin has migrated to them, starting from Forms 4.5
Here is some more information about the libraries - Introducing AndroidX for Xamarin
There is a special NuGet package for the migration - Xamarin.AndroidX.Migration. Also available is a built-in functionality in Visual Studio - here
What I can suggest is you try to migrate to AndroidX libraries, since the old support libraries won't be supported from now on, and you will surely encounter some issues if not like this one, then something else will pop-up in the future.

How to develop Android applications? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I used to be an Android developer for 2 years, but over 2 years ago. I believe that things changed - we have Android Studio, Gradle and probably more tools that I'm not aware of right now.
What is the current development stack for creating Android applications? What tools should we used right now?
I used to use eclipse with ant, but as far as I can see, a lot of people are using AS with Gradle, which is, for my first experience, extremely slow.
How to jump back into Android development after some time of not being up to date with development stack?
Eclipse vs Android Studio is a matter of choice. You can get used to it within hours, or you can continue with Eclipse. I am using both tools for different projects.
Android Studio seemed to be more stabile at some points.
Update on Android SDK and third party libraries are more easily handled with Android Studio.
Android Studio has not NDK support yet. You have to compile native codes outside of Android Studio. Edit:(Well, actually it has support but claimed to be deprecated, probably developers are working on a better solution)
Edit2:(It will be soon officially supported with C/C++ debugger)
With Android Studio you can use java7 syntax, but you have to stick with java6 syntax on Eclipse. Edit:(you can now force java8 with a plugin on A.S and I guess java7 is usable on eclipse too) Edit2:(java7 is a must now for both parties, but still java8 syntax can only be used in A.S with a help of plugin)
Google releases example codes compatible with Android Studio saying eclipse versions will be available soon.
Android Studio has better GUI designer.
Android Studio has better refactoring capabilities.
The most important change is SDK itself, actually. Just check if Android Studio is good enough for you and study on SDK.
It depends on your project. For non critical or hobby projects you should definitely start with AS and Gradle right away because this the the future of Android development. Although it is still in 'beta' and it can break some stuff after a new upgrade, it has many new features which make you more productive and happier in development.
If you have a critical project and you don't want to spend your time with checking and fixing things your are not supposed to fix, you should stick back to Eclipse, at least until AS is released.
Independently on whether you use AS or Eclipse, you should already start learning and using Gradle. It works perfectly for both options. If you hesitate you can even keep Ant and Gradle building your project in parallel. They work together and don't overlap.
I have been using Android Studio the last year and I can say that it is a very powerful tool, that I believe, in the next year, will overcome Eclipse.
When AS was still in version 4.+ Alpha, there were some issues (mostly with external libraries .jar) but since beta was released and up until now almost every bug was fixed.
Moreover, AS is better when it comes to indexing and suggestions. You will be surprised by its suggestion system, which helps you save a lot of time when coding.
I still use eclipse for other projects, but I believe for Android Development AS is the tool you should invest in, if not for now, definitely for the future.
We are using both, Android Studio and the good old Eclipse IDE. We noticed, that it basically depends on what you're doing. Android Studio is good enough for developing from now and it will replace Eclipse soon. However, it has some drawbacks where Eclipse is your choice. A small comparison was made by Google themselves: https://developer.android.com/sdk/installing/studio.html
Eclipse: Eclipse is very stable and works perfectly with ant driven builds. However, if you want to use gradle, there's some work to do to get the build process working with eclipse. We tried to use Eclipse with Gradle but the Gradle Plugin was quite buggy at this time. If you want to use native C code, you must use Eclipse, as Android Studio does not support that, yet.
Android Studio: Looks great and does also a very good job. The gradle integration works much better there. This is a big advantage over Eclipse when you have to deal with many dependencies. This is probably not an issue for small projects. But, if you're developing projects with additional libraries or frameworks you should definitely give Gradle a try. I hope, that the NDK support is coming soon, so that we can switch to AS completely. Ant builds are someway out-dated.
First of all, I will not debate about Android Studio vs Eclipse as it's an opinion based discussion and a kind of a troll...
The Android development basically the same : the base tools still ADB, Android SDK, Java language... So you can continue to use a "notepad" and compile, build and deploy by the SDK tools.
However, like in every development project, you could choose your upper level tools. Your question is about IDE and building system. This is only a matter of choice.
Android Studio and Gradle are still in beta phase for Android developments and you could use them only if you keep this in mind. You could continue to use Eclipse and Maven or switch to Android Studio and Gradle or keep using Eclipse but moving from Maven to Gradle... just make what you prefer.
The Android development stack evolved this way :
Basics tools : Text editor, SDK tools
First IDE : Eclipse with ADT plugin (can run your program from an IDE)
Industrialisation phase : Eclipse ADT + Maven (dependencies management, building process management...)
Coming phase : Android Studio (IntelliJ based) + Gradle (you can compare Gradle to Maven, but this is another discussion)
I think that other answers will give you personnal points of view about Eclipse vs Android Studio, Maven vs Gradle, etc... which is a really personnal choice ;)
My development stack for Android :
IntelliJ 14
Maven
Android SDK
plus my own OSS Framework to ease the pain of Android for a Java EE developer
Reasons:
IntelliJ is the best available IDE imo
Maven is pretty mature
The plugin has become useable
The workspace integration Maven -> IntelliJ is working great (both, using maven builds and deriving IDE builds from maven)
If Android Studio (which is in great parts IntelliJ) has become slow, it come due to the gradle stuff. I had a large scale project based on gradle and made these experiences :
Slow, Slower, gradle (up to 2GB memor consumption for building an app)
Xml is horrible, but gradle dsl is imo even worse
Switching to gradle 2.1 broke the predicate logic (e.g. formerly working project.hasProperty("foo") && property.ext.foo.equals("bar") does not work any more, this must not happen during a MINOR release
Compared with maven's xml hell, gradle leaves a callow, unmature impression on me, especially building with gradle is hell of a slow job compared with maven.
But - and this is my true oppionion - if gradle is pushed by google and gradleware, it definitely has the potential to become the next generation building tool, although I doubt that the flexibility in gradle will ever lead to a proper IDE workspace build derivation. From my point of view, the choice for gradle over maven done by google happened in a too early state.
just my two cents.
PS: Try tuning the memory settings. Give more memory to IDEA (e.g. 2GB in a 64bit enviroment). My experience with IntelliJ is, that the default mem settings are too small. You can find it in $InstallDir/bin/idea.exe.vmoptions resp. $InstallDir/bin/idea64.exe.vmoptions
EDIT: This is not intended to be gradle bashing. Gradle has large potentials indeed. This post reflects my experiences during my last project basing on gradle (non-Android). For beginners gradle might be the better choice since it is a lot easier than maven.

Unit tests in Android Studio 0.8

BREAKING NEWS: Android Studio 1.1.0 now has built-in support for unit testing. See more here: https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support
At first I know that there are very, very, very much similar questions (even here on SO). Most of them are terribly outdated so I'm asking a fresh new question which should be up to date for Android Studio 0.8.x.
I know there are some libraries which work somehow, but in almost each case I had no evidence that the information were up to date. I know there is e.g. roboelectric, there are also some deprecated Jake Wharton like gradle-android-test-plugin or double-espresso, I also found the library RoboSpock and Deckard. But none of them seems to have any Android Studio integration.
After long reseach I found this two bugs in all implementations:
The classpath is broken and needs to been hacked to get junit running
The junit tests cannot been debugged
What I'm looking for:
I want to automatically test an algorithm (which is plain java)
I want to check the integration in my Android app works
I want an integration in Android Studio so that I can jump into the code out of a stacktrace
I want to step thrue the test code
I found also somewhere a nice hack which run the tests in gradle as an external task and pushed the results into AS so that the results could been displayed, but unfortunately I cannot find that link again (and if I remember correctly it did also not work for me).
Do you guys have some fresh references? Does it work for you?
You have to edit the .iml file that Android Studio generates to point to your test-classes directory and also to fix the Stub error from Junit. There is currently no work around for this.
Gradlectric is a sample that uses the Robolectric Gradle Plugin to run unit tests in Android Studio.
Here you miss one example project setup https://github.com/nenick/android-gradle-template
But none of them seems to have any Android Studio integration.
This project is maintained for android studio
The classpath is broken and needs to been hacked to get junit running
gradle scripts will fix the classpath
The junit tests cannot been debugged
tests a running inside AS so they are easy to debug
This project of mine does not cover all your requests, but a fair lot of them.
It covers a default Java test case, and some tests interacting with Views.
The root project uses Travis CI, which uses gradle connectedCheck to run the tests. To be able to debug the tests, you can just create a test run configuration in AS and run it in debugging mode.
Note that this does not use any special Android testing frameworks like robolectric.
You can find a fork of Jake Wharton's gradle-android-test-plugin here. This is compatible with AS 0.6 and is regularly maintained by Robolectric. You can look at this project to set up Robolectric in Android Studio with help of this plugin. You can achieve fair bit of functionality you mentioned with the help of robolectric-gradle-plugin. You can also successfully debug your test code using AS.

Categories

Resources