I am a bit new to eclipse plugin development. My requirement:
I want to show warning signs(like screenshot attached) in the import statements Java files and effective pom files of Java projects based on some parameters.
Assuming eclipse already has some classes and functions for this, I would like to know what dependencies I could add in my Manifest file of my Eclipse Plugin and which class I could extend and functions I could use to implement my requirement?
Any help would be very much appreciated. Thank you.
If you're willing this to happen at same time as compilation, you can add an extension to the org.eclipse.jdt.core.compilationParticipant extension point ( https://help.eclipse.org/2019-12/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_jdt_core_compilationParticipant.html ) and implement the CompilationParticipant.reconcile() method to look at the content of the file and use putProblems() to add problems.
You can also put it in a separate builder ( https://help.eclipse.org/2019-12/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-5.htm ), or resource listener, or document listener, that would invoke file.createMarker(...) to add the error markers.
All that depends on which layer you prefer to hook onto.
I am following along with this tutorial to try and get test coverage metrics in my java + kotlin project which is built with gradle :
http://vgaidarji.me/blog/2017/12/20/how-to-configure-jacoco-for-kotlin-and-java-project/
I copy and pasted each block in, to avoid any syntax errors on my part - and am getting the following error :
Could not find method jacocoTestReport() for arguments [{type=class org.gradle.testing.jacoco.tasks.JacocoReport, dependsOn=testDebugUnitTest}
The only thing I do differently from the tutorial is drop 'task' from the line which is the signature of jacocoTestReport... because if I have it - the plugin cries that the task cannot be added, as it is already defined - as per the documentation, I removed it - so that it extends the one provided by the plugin.
Has anyone else seen this? I could really use some help - as it wont work no matter what I do. Also, this is a straight java + kotlin project, not android.
I am using Android Studio for my Android projects. I faced an issue when builds crash with strange stacktrace, like this:
Error:Execution failed for task ':app:compileDevDebugJavaWithJavac'.
java.lang.RuntimeException: failure, see logs for details.
cannot generate view binders java.lang.NullPointerException
at android.databinding.tool.reflection.ModelMethod.isBoxingConversion(ModelMethod.java:155)
at android.databinding.tool.store.SetterStore.isBetterParameter(SetterStore.java:946)
at android.databinding.tool.store.SetterStore.getBestSetter(SetterStore.java:838)
and it was seemed that the databinding became broken as whole.
I made refactoring before and moved classes between packages.
In my case, I relied on Android Studio when renaming and moving classes between packages. But it didn't proceed correction for XMLs of layouts where were references on refactored classes in the type attribute of variable element in data.
So my previous type's value pointed to non existing files and build crashed.
It's simple mistake but it may take more time to find the source. Hope this would help someone.
For me, this started happening after updating Android Studio to version 3.5.2
To fix it, I downgraded Android Gradle Plugin
buildscript {
repositories {
//..........
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
//......
}
}
Make sure you import all classes you reference in xml bindings
I had code something like:
android:visible="#{obj instanceof A}"
I was getting that same error.
Turns out that class A was not imported on top. Adding <import type="com.company.A"> tag resolved the problem.
P.S. android:visible is a custom binding adapter I have.
If this question is still relevant. For me I figured that in my xml layout file I was including a class (not an instance of one) as a variable, i.e I had this code
<variable
name="Converters"
type="com.example.flexapp.utils.Converters" />
and it should have been
<import type="com.example.flexapp.utils.Converters"/>
since this was a class and not an object.
in my case my problem was in a LongClickListener that the method for this listener must have returned a boolean but my method returned void so when I added the correct return statement it worked just fine.
keep in mind if you use a data binding method you must return the correct value or else the error it throws is not helpful at all.
You may have stumbled upon this question after migrating to Android X. If that's the case, and you're positive your XML files are okay, but it's still not working, you should start looking at libraries that generate code.
Libraries that generate code cannot be easily converted by the Jettifyer. Some info here - https://blog.danlew.net/2018/11/14/the-reality-of-migrating-to-androidx/
In my case, I updated the obvious ones, but I still was missing something. So, what I did was go into my develop branch (that wasn't Android X), ran a build, and dug into the build folder to see all of the libraries that generated code. Once I did that, I was able to look at the suspects one by one until I found the dependency that was causing this issue. You could either update it, or, in my case, remove it, and this error was resolved. :)
The getter function for any instance that you refer from your xml file might not have been defined or the getter function might not have public access specifier.
Downgrading Android Gradle Plugin to 3.5.1 fixed the issue for me
I face this problem when I define variable like this (Android Studio don't warning anything)
<data>
<variable
name="onGlobalLayoutA"
type="ViewTreeObserver.OnGlobalLayoutListener"/>
<import type="android.view.ViewTreeObserver"/>
</data>
And I solve it by
<data>
<variable
name="onGlobalLayoutA"
type="android.view.ViewTreeObserver.OnGlobalLayoutListener"/>
</data>
Hope this would help someone.
In my case, the reason was that I used a type for a variable which is another module and that module is added as 'implementation ' in build script. Changing to 'api ' resolved the issue.
Clearly not the same issue as the one posted by atlascoder but I mention regardless, maybe someone gits this article with the same problem as I had.
As #hiddeneyes02 mentioned, this started happen when upgrading from Android Gradle Plugin from 3.5.1 to 3.5.2, this seems to be the bug:
https://issuetracker.google.com/issues/143778134
When I built the project with the command tool I got the same errors as in this post:
When building Android project with Android Gradle Plugin v. 3.5.2 my builds fail
In my case I wrote wrong the name of my view model variable inside the XML file. I had it named VProgressBar instead of vProgressBar:
android:visibility="#{fatherViewModel.vProgressBar}"
This is my project stricture :
-com.android.test
--com.android.test.activity
---MainActivity.java
---SplashActivity.java
--com.android.test.ui
---ActivityBase.java
I created all activity in com.android.test.activity package and all activities extended from Base activity in com.android.test.ui package
But i don't know , when i creating activities on com.android.test.activity i see .R error in my Eclips , but when i creating activity on com.android.test package ,no need for importing the .R class.
I'm very beginner , please help
When you build an android project, the build tools generate a class called R.java. Because R is a class, it will exist in a package, just like all your other classes. By default, R will be generated in the package you've specified as the project package. For you, this should be com.android.test.
So your package structure is actually like this, even though R is in gen/, not src/.
-com.android.test
--R.java
--com.android.test.activity
---MainActivity.java
---SplashActivity.java
--com.android.test.ui
---ActivityBase.java
In Java, you will require an import statement if a class is not declared inside the package of the current class. So because com.android.test is not contained in com.android.test.activity, you will need to add import com.android.test.R; to MainActivity and SplashActivity, in order to use R in them.
If R is not being generated for you, check out Developing for Android in Eclipse: R.java not regenerating. I would possibly recommend learning to use IntelliJ IDEA, as I've encountered fewer strange build issues than in eclipse, but this is completely optional.
Another possible source of error is if you accidentally imported android.R, which is where the resources of the android SDK are referenced from. This could easily mess you up, since you could write code like R.string.foo and think you are using com.android.test.R.string.foo, but in reality, you are using android.R.string.foo, which may not exist. An easy way to find the problem is to explicitly say in your code, for example:
// you were originally getting an error here
MyActivity.this.getString(R.string.foo);
// try this to get a more obvious error, or see if it fixes it
MyActivity.this.getString(com.android.test.R.string.foo);
There are numerous examples showing how to get the package name in code at runtime.
In my case, I need to test the package name at compile time.
Here is my situation: I have two Android projects (the free and the pro) which leverage a library project.
The free version has a "Get the pro version" menu item, which does not exist in the other version.
My menu handling code goes like this:
if ( item.getItemId()==R.id.getProVersion ) {
//...
}
Proguard complains that R.id.getProversion does not exist when building the pro package.
So I need to test which project is being built, to exclude this part of the code from being compiled.
Is there a way to know the package name at compile time ?
Are there alterative solutions to this problem ? Either Android-centered or java-centered solutions are fine.
You can put the menu item in the library project, and then use the runtime package name checks to actually decide whether to display the message or not
You could do that by writing a simple annotation that automatically skips this peace of code. Myabe it's overkill, but it's also a good way to get into preprocessing...
This seems to be a good (KISS) tutorial on the topic:
http://blog.christoffer.me/2011/08/how-to-enforce-static-methods-on-class.html