Fix compile time error with Kotlin 1.8.10 - android

In an Android app I'm using Kotlin 1.7.20 and I'm trying to switch to Kotlin 1.8.10 but I'm getting the error:
1: Task failed with an exception.
What went wrong:
Execution failed for task ':useraction:kaptGenerateStubsDebugKotlin'.
'void org.jetbrains.kotlin.incremental.FileUtilsKt.cleanDirectoryContents(java.io.File)'
Try:
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
Unfortunately it isn't clear what is triggering the call to cleanDirectoryContents.
I know that Kotlin 1.8.0 introduced a change around that features but I didn't find any tutorial for the migration.

It looks like it was a problem with the gradle cache although I can't be sure.
When I upgraded the gradle wrapper to 7.6 from 7.3.3 suddenly it started working. I tried to reverse the change to reproduce the issue again and I couldn't.
I can't really point to the thing that fixed it

Related

Unable to find Gradle tasks to build: [:]. Build mode: ASSEMBLE. Tests: All

I am going through Android Tutorials to learn how to code. I haven't dealt with Gradle before. So I am having a hard time understanding the error codes. I build a very basic app.
When I go to build and click Make Project I get a weird error at the bottom:
And it doesn't do much after that. I am not sure if that is a warning that I can ignore or not. When it comes to Android dev, I am just a spring chicken.
EDIT: If i run the gradle.bat file from the command line I get this:
C:\git\Others\android-code\MyTestApp>gradlew.bat
Starting a Gradle Daemon, 2 stopped Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\git\Others\android-code\MyTestApp\build.gradle' line: 7
* What went wrong:
Plugin [id: 'com.android.application', version: '7.4.0', apply: false] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:7.4.0')
Searched in the following repositories:
Google
MavenRepo
Gradle Central Plugin Repository
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 6m 14s
Any help would be appreicated. I cant even get through the tutorial with these errors!
If you use a proxy I suggest You look at this issue.
Pay attention to it:
Also I had clean my proxy in gradle.properties. Don't know if there is
any check that I have left.
Thx I finally found the problem:
After I set the proxy in Android Studio, it set the proxy to the file
in /User/.gradle/gradle.properties
Thanks again for your help and sorry for the bothering.

flutter build apk results in "R8: Type [...] is defined multiple times"

I am developing a flutter app for Android. For that I am using a realm database and I am using the realm dependency for flutter https://realm.io/realm-flutter/ to read data from it. This realm database is generated by some android library com.my_realm_generating_library.
My problem is now, that com.my_realm_generating_library imports the realm library for kotlin https://realm.io/realm-kotlin/ and because I am importing the realm library for flutter, the kotlin library is included a second time.
When I run flutter build apk I get this result:
Running Gradle task 'assembleRelease'...
Realm binaries for realm#0.8.0+rc already downloaded
Realm install command finished.
ERROR:/home/user/.gradle/caches/transforms-3/c90739e9642326489e851a982778d55f/transformed/jetified-realm-android-library-10.6.1-runtime.jar: R8: Type io.realm.BuildConfig is defined multiple times: /home/user/.gradle/caches/transforms-3/c90739e9642326489e851a982778d55f/transformed/jetified-realm-android-library-10.6.1-runtime.jar:io/realm/BuildConfig.class, /home/user/projectname/build/realm/intermediates/runtime_library_classes_jar/release/classes.jar:io/realm/BuildConfig.class
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
> Compilation failed to complete, origin: /home/user/.gradle/caches/transforms-3/c90739e9642326489e851a982778d55f/transformed/jetified-realm-android-library-10.6.1-runtime.jar:io/realm/BuildConfig.class
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
Running Gradle task 'assembleRelease'... 9,2s
Gradle task assembleRelease failed with exit code 1
When I remove the realm library from my pubspec.yaml, everything compiles. But I need access to my realm file from my kotlin code and my dart/flutter code. Is there some way to fix such dependency conflicts, where flutter uses a library and kotlin the same and in the end none of them work?
What I tried so far:
I removed realm: ^0.8.0+rc from the dependencies section of my pubspec.yaml. Then everything compiles. This is not an option because I need this library in my dart code.
I could also remove implementation "com.my_realm_generating_library" from android/app/build.gradle. But I also need this library in my kotlin code to generate my realm database. Therefor this is also no option.
Amazingly I was able to find an answer for my question, although I was unable to find one anywhere online so far. Hopefully this helps some people who get into the same trouble as I have.
Firstly, I navigated into my projectname/android and ran ./gradlew app:dependencies --console=rich to find all the dependencies of com.my_realm_generating_library.
In my case, the only dependency of com.my_realm_generating_library was io.realm:realm-android-library:10.13.0. I knew that this package will be provided by the realm-flutter dependency. Therefor I knew, that I can just force disable all transitive dependencies of com.my_realm_generating_library.
The code I put in my build.gradle under the dependencies section was this:
implementation("com.my_realm_generating_library") {
transitive = false
}
Now everything works. Hope this helps!

Flutter issue: 'ChipsInputState' is missing

I'm currently learning Flutter using Android Studio but I can't figure this issue help pls thank you :(
Compiler message:
../../.pub-cache/hosted/pub.dartlang.org/flutter_chips_input-1.3.1/lib/src/chips_input.dart:42:7:
Error: The non-abstract class 'ChipsInputState' is missing
implementations for these members:
- TextInputClient.connectionClosed Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class ChipsInputState extends State>
^^^^^^^^^^^^^^^ ../../flutter/packages/flutter/lib/src/services/text_input.dart:658:8:
Context: 'TextInputClient.connectionClosed' is defined here. void
connectionClosed();
^^^^^^^^^^^^^^^^ Target kernel_snapshot failed: Exception: Errors during snapshot creation: null build failed.
FAILURE: Build failed with an exception.
Where: Script '/Users/clyde/flutter/packages/flutter_tools/gradle/flutter.gradle'
line: 780
What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.
Process 'command '/Users/clyde/flutter/bin/flutter'' finished with non-zero exit value 1
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 18s Finished with error: Gradle task assembleDebug
failed with exit code 1
If you are using Flutter Form Builder, you can manually update the flutter_chips_input library to the latest version because the Flutter form builder uses an old version.
This issue was discussed in the Flutter GitHub repository Issues section here.
Adding the below dependency manually to the pubspec.yaml file solved the problem for me:
flutter_chips_input: ^1.9.4
I am guessing you are on dev or master channel (at least that is the cause in my case)...you can switch to beta or stable to get rid of the error:
flutter channel beta|stable
I have also faced the same problem and not sure how that was fixed.
I have tried the following things
Check Flutter Doctor and fix if you have any errors
Try Flutter clean
Delete pubspec.lock file and run flutter pub get or flutter pub upgrade
I Hope, that may help you guys.
What worked for me
Look for packages in your pubspec.yaml file that depend on the chips_input package, e.g. form_builder and make sure it's the latest version.
Upgrade all packages in pubspec.yaml file to be sure.
I've been stack with the same error. I've searched and tried everything and nothing works.
Based on searching, the issues may have been caused by using flutter_form_builder package on an incompatible version of flutter SDK.
What works for me (Windows user):
Tried switching to master|stable version
Deleted all flutter and pub temp directories/folders:
Navigate to C:/Users/(Current User)/AppData/Local/Temp/ and delete all directories/folders having
flutter_tool.xxx, native-platformxxx, and pubxxx
Installed the latest version of Flutter SDK.
https://storage.googleapis.com/flutter_infra/releases/stable/windows/flutter_windows_1.17.3-stable.zip
Tried Flutter clean
Deleted pubspec.lock file and run flutter pub get or flutter pub upgrade
Upon building my project, another issue pop-up, NDK version not found. Instead of downloading the required NDK, I removed/renamed the NDK directory/folder from my Android SDK directory/folder.
Hope this steps helps.

Update to Gradle 5.1.1 gives "The ProjectLayout.fileProperty() method has been deprecated"

I am working on a project that previously used Gradle 4.6 and it worked fine. I just updated to Gradle 5.1.1 and I am now receiving the following warnings (Not sure they are warnings or errors, though):
> Configure project :app
Warning: Please apply google-services plugin at the bottom of the build file.
The ProjectLayout.fileProperty() method has been deprecated. This is scheduled to be removed in Gradle 6.0. Please use the ObjectFactory.fileProperty() method instead.
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
FAILURE: Build failed with an exception.
* What went wrong:
Failed to notify build listener.
> org.jetbrains.plugins.gradle.tooling.util.ModuleComponentIdentifierImpl.getModuleIdentifier()Lorg/gradle/api/artifacts/ModuleIdentifier;
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
CONFIGURE FAILED in 0s
Cause: org.jetbrains.plugins.gradle.tooling.util.ModuleComponentIdentifierImpl.getModuleIdentifier()Lorg/gradle/api/artifacts/ModuleIdentifier;
I searched for ProjectLayout.fileProperty inside the whole project and didn't find a single string like that. Where is fileProperty used then causing the compiler to complain? How can I fix these deprecation warnings rather than suppressing them? Is there a part of my code I need to change? Or does the usage pointed to by compiler occur inside one of the libraries I have added?
These are warnings, not errors, and can come either from your own build scripts, or as it seems to be the case here, from a plugin.
These warnings, as they indicate, can become errors only when moving to the next Gradle major version.
In the case the source of the warning is inside your build script, you should try to make them go away as fast as possible. That way upgrading to the next Gradle major version will not be a problem.
When coming from a plugin, if you can identify the right plugin, upgrade to a more recent version and file an issue if the warning persists. This way you have a better chance that the plugin keeps working with the next Gradle major version.

Cannot invoke method containsKey() on null object

I got this error when I was building my Android project by gradle. It roughly happened once per week.
FAILURE: Build failed with an exception.
* What went wrong:
Failed to capture snapshot of input files for task ':xxxxxxxx:compileDebugAidl' property 'importDirs' during up-to-date check.
> Cannot invoke method containsKey() on null object
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Any idea what may cause this error? thanks
From #tapchicoma comment to the original question, the issue: NullPointerException in Google Services Plugin now is marked as fixed for 4.2.0.
So, the final solution is to update to:
classpath 'com.google.gms:google-services:4.2.0'
Until the bug is fixed by google, downgrading to the play services 4.0.1 seems to have fixed this issue for me so far:
classpath 'com.google.gms:google-services:4.0.1'
https://stackoverflow.com/a/50930048/4096987

Categories

Resources