On ${CMAKE_CURRENT_SOURCE_DIR}/JUCE, there is:
option(JUCE_BUILD_EXTRAS "Add build targets for the Projucer and other tools" OFF)
if(JUCE_BUILD_EXTRAS)
add_subdirectory(extras)
endif()
link: https://github.com/juce-framework/JUCE/blob/master/CMakeLists.txt#L57
So this is what I did:
set(JUCE_BUILD_EXTRAS OFF)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/JUCE)
However it still tries to build extras. I'm on Android Studio.
What should I do?
I also tried set(JUCE_BUILD_EXTRAS OFF)
The default value is OFF and even then it tried to build.
I always get these errors when trying to disable something on Android CMAKE but it always fails
The easiest way to guarantee that this will be overridden correctly from a parent CMakeLists.txt is to set it as a CACHE variable with a FORCEd value:
set(JUCE_BUILD_EXTRAS OFF CACHE BOOL "" FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/JUCE)
This will ensure that any state that may already exist from a previous configuration of the project that defines the option will be overridden and picked up first.
Technically, the documentation for option states:
... If is already set as a normal or cache variable, then the command does nothing.
However, this is only true if there have been no prior configurations -- so this only works if the variable was set before the first configuration
In practice I've found that the FORCE-approach is much more reliable.
Related
Unfortunately I came across this issue quite often already.
In my Android project I am using databinding to bind classes to my xml layouts which works fine. Basically I am doing it the following way:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="myClass" type="com.somepackagename.myClass" />
</data>
</layout>
Throughout my (quite large) project, i am frequently using the same variable name for many different xml layouts.
After doing a lot of refactoring, I can now no longer build my project due to the following build error:
e: error: Cannot resolve type 'myClass'
e: error: cannot generate view binders android.databinding.tool.util.LoggedErrorException: failure, see logs for details.
Cannot resolve type 'myClass'
at android.databinding.tool.util.L.printMessage(L.java:134)
at android.databinding.tool.util.L.e(L.java:107)
at android.databinding.tool.expr.Expr.getResolvedType(Expr.java:386)
at android.databinding.tool.expr.ExprModel.lambda$resolveTypes$1(ExprModel.java:618)
...
While the errorMessage is clear to me and tells me which variable name is causing this issue, unfortunately it is not very verbose and does not tell me:
which xml file causes this problem
which specific type causes this problem
This makes it extremely hard to find the causing issue if you've changed many xml layout.
Isn't there a better way to debug such errors?
After spending many hours, I finally found out what was causing the issue.
I found a way to debug such errors in a way that one should always find the issue relatively quickly. The setup however for this takes quite a few steps though:
First of all, I want to thank the author of this excellent article who gave me a good idea where to start:
https://medium.com/#dzolnai/debugging-a-databinding-compiler-error-9510f88f4cec
Based on the above article, here is how you should be able to find the causing error quickly.
Add a new configuration in Android Studio: Edit → Run configurations. Give it an arbitrary name, for instance DatabindingDebugging and click OK (i.e. nothing should be changed)
In a terminal window execute: ./gradlew assembleDebug --no-daemon -Dorg.gradle.debug=true -Dkotlin.compiler.execution.strategy="in-process" -Dkotlin.daemon.jvm.options="-agentlib:jdwp=transport=dt_socket\,server=y\,suspend=n\,address=5005". The build should print > Starting Daemon. I.e. it waits until you debug.
Back in Android Studio, on the top section your new configuration DatabindingDebuggingshould be selected. Click the green debug icon Debug DatabindingDebugging or press Ctrl + D
The debug window should now launch and indicate something like Connected to the target VM....
In the meantime, back in your terminal window, the gradle build should now execute as usual.
In the debug window in Android Studio, manually add a new Breakpoint: Click ViewBreakpoints (red icon with 2 dots). In the Breakpoints window add a new Breakpoint by clicking the + icon on the top left and select 1. Java Method Breakpoints
In the pop up enter the following:
Class pattern: android.databinding.tool.util.L | Method name: printMessage and click OK.
Make sure that both the Enabled and Suspend checkbox are checked. Also make sure to check the Condition checkbox and enter the following expression: kind.name.equals("ERROR"). This way we instruct the debugger to only suspend if the databinding tool prints a log message with an error.
Click Done.
At some point during your build, if you have a databinding ERROR, a breakpoint should be reached. In the debugger you should now see the exact error message the logger printed: Cannot resolve type 'someType'
Now scroll down the Stacktrace on the left pane of the debug window and click the entry getResolvedType:386, Expr. On the right pane you should now see the causing type for the error: this.mUserDefinedType = "com.somepackagename.myClass".
The final step is easy. Using Android Studio, simply search for this class, for instance using: Edit → Find → Find in Path → "com.somepackagename.myClass". On the right side of the window, select File mask: *.xml You should now see all xml files that caused the issue.
Hope this helps someone in the future. Still IMO this is way to complicated. If anyone knows a better way to debug such issues, please let me know :)
I know I could set a breakpoint at every line where my code changes the variable, but is there an option such as right-clicking a variable (to "Add to Watches") that would stop when a variable changes value?
I think C++ has this option. See this.
And Eclipse? See this.
Is this implemented in AS?
You can break on value changes of some variables in Android Studio 1.1.0.
Android Studio calls them 'Java Field Watchpoints'.
From the breakpoints windows, (Run -> "View breakpoints...") or Ctrl+Shift+F8,
you can add "Java Field Watchpoints" from the plus in the top left corner, and then select your class and variable.
If the goal is simply to set a watchpoint where execution halts if a variable's value changes, there are two methods:
Pressing Ctrl-shift-F8 to set a watchpoint brings up this dialog:
That looks more powerful but it's confusing because it lacks the option I need; and there's an extra step: filling in the dialog box below:
Once you fill it in correctly, you get the same options for stopping execution as in the simpler method below:
Define the variable on one line ending with a semicolon.
Left-click in the area where you set a normal breakpoint and up pops a dialog box.
Choose options to suit your needs.
Any instance where the value of the variable prefDbExists changes, execution will pause as at any "normal" (unconditional) breakpoint. And that's all I needed when I asked the original question.
EDIT: Fully qualified class name is {package name}.{class name})
What you seek for is commonly known as "WatchPoint".
You will find detailed answer and examples on the doc. page of JetBrains - IntelliJ - Idea which is the basis for Android Studio.
https://www.jetbrains.com/help/idea/2016.3/creating-field-watchpoints.html
For me this works perfectly !
Add a Kotlin Field Watchpoint by clicking on the space next to the line number for the field declaration in Android Studio. Select Kotlin Field Watchpoint from the Set Breakpoint menu. You will now get a breakpoint whenever that value changes.
How can I create a layout file with data and fill them with some example data so that I can see what I have done without producing warnings.
Here is an example:
If I remove the text (which wants Android Lint) I have a plain blue screen, which is not helpful at all.
By the way this is the warning:
[I18N] Hardcoded string "Foobar", should use #string resource example.xml /Example/res/layout Line 42 Android Lint Problem
Create an entry in your strings.xml for each of your example Strings.
On the other hand, this is a Lint warning. You can safely ignore this without causing immediate harm to your app, as these are only meant to guide you in best practices.
Go to the Eclipse preferences, into the Android submenu, then into the Lint Error Checking menu and disable the HardcodedText warning.
Second Method
Instead of setting the example text through XML, use the setText() through Java code, and enclose it in an if condition as follows:
if(BuildConfig.DEBUG) {
view.setText("My example text");
}
BuildConfig.DEBUG was added in ADT 17, and is true whenever you do a debug build. When you export the apk, it is set to false. As the variable is set to false and never reassigned, the Java compiler will optimize your code and remove these statements. They will not be compiled into a production app.
Since ADT 17 you can find in the gen folder a BuildConfig class with a DEBUG constant. I often use this constant in my code, since ADT changes the value automatically when you export the application.
However with Proguard this doesn't work anymore. E.g. I have following snippet:
if (!BuildConfig.DEBUG) {
ACRA.init(this);
}
Proguard notices, that DEBUG is true, so it removes this snippet completely and shrinks the app. After that ADT changes DEBUG constant, but this is too late.
The only solution I know is to create my own DEBUG constant and to change it manually again. But I really like the functionality of ADT. Do you know a better solution?
Thanks in advance.
Edit:
There is a workaround. Create your own DEBUG constant, which is initialized at runtime:
debug = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
I create this variable at the very first in the onCreate method of my Application class. That is a workaround, which works, but it isn't the solution of the problem.
For some reason auto complete no longer works. for example when writing code using the android bitmap class, when i use the dot operator eclipse would suggest methods for that object instance. how do you turn this feature back on?
thanks mat.
I had this same problem. Here is how I solved it.
In Eclipse go to
Window -> Preferences -> Java -> Editor -> Content Assist -> Advanced
And check the boxes labeled "Java Proposals" and hit Apply.
Im my case was API tools proposals the option that cause my autocomplete doesn´t work, here are the 4 default options that must be checked...
API Tools Proposals.
Java Proposals.
SWT Template Proposals.
Template Proposals.
the next time i must be careful when click Ctrl+Space =D
Go to Preferences > Java > Editor > Content Assist and paste "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz." (note the dot after z) into the "Auto activation triggers for Java:" field.
This worked for me ! Now as i type I get autocomplete options
Here's another solution I dicovered:
I would check the other solutions listed here first and if all else fails shut down eclipse then delete the file 'org.eclipse.jdt.ui.prefs' found in the workspace directory (Workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings).
Seems in my case the workspace became corrupted somehow and this fixed it. Haven't yet noticed any adverse effects by doing this.
eclipse use "ctrl+[space]" to show the "css/html/java proposal"
I had the same problem and none of the solutions here worked. For some reason, my Scheme had changed from "default" to "Emacs". So to fix it, I had to go:
Preferences> General> Keys and change the scheme back to default.