A failure occurred while executing org.jetbrains.kotlin.gradle.internal - android-studio

Building of my android app failed with a new strange set of errors:
theapp/app/build/generated/data_binding_base_class_source_out/debug/out/com/comTest/theapp/databinding/TabPinBinding.java:48: error: illegal '.'
public final com.comTest.theapp..utilsviews.MyTextView pin8;
The class MyTextView is defined in theapp/utils/views/MyTextView.kt
it looks like the generator of java code makes a mistake.
As this code is right in generated java, I don't know how to correct the error or where to begin with to fix the problem.
The application compiled fine then I did the following:
created a scratch.kt file where I needed to import some file defined in the utils folder
updated some stuff (gradle pluggin, targetSDK value, remove redundant dependencies) following suggestion of android-studio. It was the usual stuff when updating android-studio internals.
the errors appear in the file TabPinBinding.java which start with:
"// Generated by view binder compiler. Do not edit!"

I find the error.
It comes from a layout not used anymore in the project.
<?xml version="1.0" encoding="utf-8"?>
<com.comTest.theapp..utilsviews.PinTab
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pin_lock_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.comTest.theapp..utilsviews.MyTextView
android:id="#+id/pin_lock_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/small_margin"
android:paddingLeft="#dimen/activity_margin"
android:paddingRight="#dimen/activity_margin"
android:paddingTop="#dimen/activity_margin"
android:text="#string/enter_pin"/>
<!-- other fields -->
</com.comTest.theapp..utilsviews.PinTab>
I do not know why the layout uses a wrong path to access the Layout class defined in the project but I suspect a bug of the IDE when propagating changes related to renaming or moving of the Layout class file.
This change was made a long time ago, and gradle and android studio seemed to have ignored the problem so far. Why it pops up now ?
I have updated the kotlin version to Java 8 (sourceCompatibility "1.83) and other changes. It looks that many problems are poping up...
To find the problem I made a search on the entire project with the string com.comTest.theapp..utilsviews
To remove the problem, I corrected the paths in the layout to : com.comTest.theapp.utils.views wherever the error occured.

Related

Android studio problem with configuration: type mismatach problem

I wrote a code like that:
var btn: Button = view.findViewById(R.id.btn)
view.findViewById(R.id.btn) is red underlined.
It's working fine but Android studio tolds me that it is mismatch type (Compiler expected View!). It had been working fine until i changed a profile from debug to release. Since that it show me errors.
And one more error which i recived is with:
view.findViewById<TextView>(R.id.user_name)
TextView is red underlined.
No type args expected for fun.
I belive that error s only becouse of android studio config. I can compile my code witout any problem, but android studio doesn't suggest me things like that.
Have you maybe any suggests ?
Have you tried to rebuild and clean your code? #Young_User
Might be an issue with what you are inheriting in your class.
Care to share the error code and full class too?

Android Studio Kotlin databinding: Unresolved reference on BR

I have some code that is generating a "red squiggly" error in Android Studio:
#get:Bindable
var title: String = ""
set(value) {
field = value
notifyPropertyChanged(BR.title)
}
It complains that "title" is an unresolved reference on BR.title. Building and running works fine though, and this is the only error I can see. I debug there and see that it's gotten the value for BR.title correctly.
Still, I can't figure out how to make it go away. I verified that the generated BR class has the "title" field, but Android Studio refuses to recognize this. I've looked up people having this issue and have tried the following: (unsuccessfully)
Closing Android Studio, deleting the .gradle, .idea and build folders and restarting
Build -> Clean Project, Rebuild Project
File -> Invalidate Caches and restart
Disabling and enabling the Kotlin plugin
Closing and reopening the project
I have also checked and I have apply plugin: 'kotlin-kapt' in build.gradle.
Anyone know what's going on? I assume it must be holding onto some cache files somewhere but I don't know where.
What fixed the problem for me was adding the following import to my files:
import androidx.databinding.library.baseAdapters.BR
I'm not entirely certain why this works, but it got rid of all the analysis problems and the application still compiles and works fine, so I'm personally happy.

Typescript giving "Output Generation Failed" in Visual Studio 2012 with 0.9.5

I've been using Typescript 0.9.5 for the last few days, and then suddenly today the JavaScript files just stopped being generated. I see an error "Output generation failed" in the Visual Studio status bar, but nothing in any of the output windows.
I've rebooted, and restarted Visual Studio, disabled Web Essentials, tried all the usual things.
The files are set as TypescriptCompile in the properties. I've tried adding new files, or editing old ones with no effect. The Project file hasn't been changed as far as I can tell (its in TFS and none of the TypeScript sections have been altered).
I've made sure both files are checked out, still nothing.
Update: I've managed to compile manually using tsc.exe from the command line, so it must be something in Visual Studio.
OK, so I solved the problem.
One of my files contained invalid typescript, specifically trying to export a class when not inside a module. This caused all typescript files to fail to generate, but with no useful error message.
The following file would cause the problem:
export class Test {
public DoSomething() {
}
}
Either removing the export keyword, or adding a wrapping module solved the problem.
I've raised it as an issue here: https://typescript.codeplex.com/workitem/2109
Update: More details.
The above syntax is valid if you are using the CommonJS or AMD module patterns.
To enable this in visual studio you need to edit the .csproj file and insert a new PropertyGroup:
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
If you have an export outside of an internal module Typescript tries to compile it as either commonjs or amd module format. The compilation will fail if the a --module flag is not present on the command line. Use your project properties to set it to the desired value (probably amd in your case).
More info on TypeScript modules : http://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1

Gradle merge wrapper/sub-module's Android manifest into a main module's manifest

I have the following modules inside my project for which I cannot get Gradle to merge the Android manifests properly:
myproject_alpha
myproject_beta
myproject_lib
myproject_release
The *_lib module is the main module for the project that contains all source code. The other 3 modules are "wrapper modules" that make slight modifications to the content providers' "authorities" parameter, change the "data" field inside an activity's intent filter specified in the *_lib module's manifest, plus enable some other activities not present in myproject_release module.
Currently, I have gradle Android manifest merging errors between alpha (or beta or release) vs lib. For example, between lib and alpha I see the following 2 gradle errors:
Trying to merge incompatible /manifest/application/provider[#name=com.myproject.contentprovider.MyProvider] element:
<provider
-- #android:authorities="com.myproject.alpha.provider"
<provider
++ #android:authorities="com.myproject.lib.provider"
:myproject_alpha:processDebugManifest FAILED
Trying to merge incompatible /manifest/application/activity[#name=com.myproject.activity.LoginActivity] element:
<activity
#android:name="com.myproject.activity.LoginActivity"
#android:name="android.intent.action.MAIN">
#android:name="android.intent.category.LAUNCHER">
<intent-filter>
#android:name="android.intent.action.VIEW">
#android:name="android.intent.category.BROWSABLE">
#android:name="android.intent.category.DEFAULT">
<data
-- #android:host="myhost.test.com"
<activity
#android:name="com.myproject.LoginActivity"
#android:name="android.intent.action.MAIN">
#android:name="android.intent.category.LAUNCHER">
<intent-filter>
#android:name="android.intent.action.VIEW">
#android:name="android.intent.category.BROWSABLE">
#android:name="android.intent.category.DEFAULT">
<data
++ #android:host="myhost.com"
:myproject_alpha:processDebugManifest FAILED
The only similar question I found was
Gradle: How to merge Android manifest files for different buildTypes which need the same Activity, but with different intent-filters. However, it doesn't really match my issue because in my case "lib" and "alpha" are interdependent modules not different builds. I'll appreciate some feedback.
I have issues with the answer above in that when I compile, I always get the message
Invalid instruction 'merge', valid instructions are :
REMOVE,REPLACE,STRICT
I found success in importing the tools as in #swooby answer and then adding tools:node="merge" in the <activity> tag for the Activity being launched I want to replace and then adding
<intent-filter tools:node="remove">
<action android:name="android.intent.action.MAIN"/>
to the Activity's launcher that I do not want to have a launcher icon
Hope this helps.
If you examine the class that merges the manifests, you'll see that the mergeNewOrEqual() method is not smart enough to merge elements that are not identical. Unfortunately, this is the method that is used to merge providers and activities.
So the only "solution" would be to either to only define the elements in one place, or to give them identical signatures in both definitions.
Declare the header of your manifest as follows:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
Then, use one of the following appropriate attributes on any activity, activity-alias, service, receiver, or provider element that you want to merge:
tools:merge="override"
tools:merge="remove"
This info was gleaned from:
https://android.googlesource.com/platform/tools/base/+/idea133/build-system/manifest-merger/src/main/java/com/android/manifmerger/ManifestMerger.java

PostSharp warnings when using fakes in VS2012

We've updated to VS2012 recently and also changed our PostSharp version to 3.0.26. Generally this combination works fine, but I get warnings for my unit test project such as
The module "MyModule.Fakes.dll" does not contain any aspect or other transformation. For improved build-time performance, consider disabling PostSharp for this module by setting the compilation symbol (aka constant) "SkipPostSharp" in your project or set the MSBuild property "SkipPostSharp=True".
Now usually I can disable this warning by changing the project settings accordingly (SkipPostSharp = True), but I've already done that for my MyProjectTest project containing the unit tests.
When I add <SkipPostSharp>True</SkipPostSharp> to my MyModule.Fakes file in the Fakes folder, the warning about PostSharp disappears, however, I get another error message:
The element "Fakes" in namespace "http://schemas.microsoft.com/fakes/2011/" has invalid child element "SkipPostSharp" in namespace "http://schemas.microsoft.com/fakes/2011/". List of possible elements expected: "StubGeneration, ShimGeneration, Compilation" in namespace "http://schemas.microsoft.com/fakes/2011".
Update
I also tried editing the fakes.xsd file and add an extra SkipPostSharp element, but a) this still isn't recognised as a valid element by Visual Studio and b) I'm not sure whether this would be the right approach anyway.
Any ideas how to get rid of these warnings?
You can specify additional properties for the project file Fakes will generate to build the fakes assembly by placing Property elements inside of the Compilation element at the end of the .FAKES file. Here is an example based on your description.
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
<Assembly Name="MyModule"/>
<Compilation>
<Property Name="SkipPostSharp">True</Property>
</Compilation>
</Fakes>

Resources