Could not reserve enough space for object heap: Android Studio - android-studio

This is occurring in Android Studio during "gradlew build".
Error: "Error occurred during initialization of VM Could not reserve enough space for 3174400KB object heap" (3.18GB)
I've tried -Xmx and the object heap has always expanded to surpass. My 32 bit software can't go much further.
"org.gradle.jvmargs=-XX:MaxHeapSize=4000m -Xmx4000m" was added to the gradle properties file.
The project folder itself only takes up 1.1GB so I'm confused as to how this is even possible.
Update:
This issue seems to have resolved itself.

add : android:largeHeap="true" to manifests
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:largeHeap="true">

Related

A failure occurred while executing org.jetbrains.kotlin.gradle.internal

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.

Conditionally exclude files from VisualStudio 2013 C++ project based on file name

I'm trying to get Visual Studio 2013's msbuild .vcxproj to automatically mark certain .cpp project files as <ExcludedFromBuild>true</ExcludedFromBuild> based on the .cpp filename.
My goal is to allow my program (~100 developers, ~1000 vcxproj) to easily support Debug only compilations of unit test code, that would all be written in .cpp files that had a _utest.cpp suffix. Any .cpp files that ended in _utest.cpp would be automatically excluded from a release build, and the programmer could see that in Visual Studio's Solution Explorer when they were switched to a Release Solution Configuration.
I have been able to prevent the _utest.cpp-suffixed files from building in Release by adding this to my shared .props file
<Target Name="Remove _utest.cpp" BeforeTargets="ClCompile" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ItemGroup>
<ClCompile Remove="*_utest.cpp" />
</ItemGroup>
</Target>
but that doesn't give a visual indicator in Solution Explorer that the files are not part of the Release build.
I already tried a condition in an ItemDefinitionGroup that was based on %(Identity) but that didn't work
<ItemDefinitionGroup Condition="'%(Identity)'=='throttle_utest.cpp'">
<ClCompile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
</ItemDefinitionGroup>
(Visual Studio refused to load this one with an error "The reference to the built-in metadata Identity at position 1 is not allowed")
or
<ItemDefinitionGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch(%(Identity), '_utest\.cpp$'))">
<ClCompile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
</ItemDefinitionGroup>
(Visual Studio loaded with this change, but did nothing to exclude the matching files from building).
Is there a way I can conditionally exclude files based on filename and get a visual indicator in Solution Explorer?
I think something like this should work.
Right under the <Project> tag.
<ItemGroup Condition="'$(Configuration)'!='Debug'">
<ClCompile Include="*_utest.cpp">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
</ItemGroup>
This works for me (was done entirely in VS2013 UI - right-click on Properties of source file and select Excluded from build: True for Release Configuration):
<ClCompile Include="foo_utest.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
NOTE: According to https://learn.microsoft.com/en-us/cpp/ide/vcxproj-file-structure?view=vs-2017 :
The Visual C++ project system currently does not support wildcards in project items.
For example, this is not supported:
<ClCompile Include="*.cpp"/>
Therefore each file should be excluded individually.

Warning LNK4075 when a C++/CLI project references a static lib project with /ZI (Edit And Continue)

I have the following projects in a Visual Studio 2012 solution:
Native (no /clr) static lib project, compiled with /ZI for Edit And Continue.
C++/CLI DLL project, which references the above static lib.
The C++/CLI project builds with the following warning:
warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification
If /OPT:NOLBR is added to the linker options of the C++/CLI project, the warning becomes:
warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
Any attempt to change the incremental linkage setting of the C++/CLI project doesn't change the warning (C++/CLI projects never link incrementally anyway).
I understand that I won't be able to use Edit And Continue in the C++/CLI project, because this is not supported. Indeed, changing /ZI to /Zi (disabling Edit And Continue) in the static lib project eliminates the warning, but I can't do that - other non-CLR consumers of that lib need to use Edit And Continue.
How can I get rid of this warning without disabling Edit And Continue in the static lib (and hopefully without maintaining separate build configuration for native and CLR users of the static lib)? I mean, is there any way to ask the linker to ignore the /EDITANDCONTINUE directive that is embedded in the referenced static lib (much in the same way that /NODEFAULTLIB can ignore /DEFAULTLIB directives)?
I have created a minimal VS solution that reproduces the described issue.
due to '/OPT:LBR' specification
This is a nonsense error message, that linker option is only effective for ARM binaries. This is simply a bug, using /OPT:NOLBR takes the sting out of it and you get the real warning.
Which is accurate enough, although it doesn't win any prizes either, you asked for Edit+Continue support in your static lib project but that is not available for a mixed-mode .NET assembly. The undocumented /IGNORE linker option is available to suppress warning messages but this one is ranked as an "unignorable warning" by Chapell.
You'll have to live with this warning as long as you don't want to change your static lib project. It is completely benign. You won't get it when you recompile it with /Zi.
There is no other way than to
disable "Edit And Continue" in the library
create a separate build configuration for "Edit And Continue (/ZI)" and "Program Database (/Zi)"
Of course: I am not aware that there is a predefined macro to determine between /ZI and /Zi... so you need to define your own preprocessor directive to distinguish between these configurations...
I had the same problem and found the only solution is to delete the .vcxproj and .sln files of the project and create the project again.
But then in an old copy of the same project I found a better solution: I changed in the projectname.vcxproj file the line
Profile true
to
Profile false
and LNK4075 warnings disappeared.
It had been the Visual Studio Profiler who had caused the troubles.

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

Visual Studio 2012 undocumented warning C4447

dllmain.cpp(16): warning C4447: 'main' signature found without threading mode
l. Consider using 'int main(Platform::Array<Platform::String^>^ args)'.
Above is a warning I got from building a Windows Store App DLL project. I didn't change anything in that default dllmain.cpp file except for including my own version of pch.
The documentation for this warning (along with many VS2012 errors/warnings) is nowhere to be found on MSDN and here is the only relevant link I can find:
http://social.msdn.microsoft.com/Forums/en-US/vssetup/thread/6daa9587-fe54-4e84-a8b9-0e5c52c2f6e8/
and the op there didn't get an answer.
If anyone knows what it means and how to fix it, it would be great!
As far as I can tell, you can safely ignore the warning. The compiler cribs when it sees a Win32-style DllMain being compiled using the /ZW flag (Consume Windows Runtime Extensions). However, the function gets called as you'd normally expect.
Alternatively, you can work around the warning by compiling dllmain.cpp without /ZW. You might need to adjust the PCH settings for this to properly work. This is the path taken by the DLL (Windows Store apps) C++/CX project template in Visual Studio.
Incidentally, the reason you do not get the warning when you're trying to build a Windows Runtime Component project (which builds everything using /ZW) is that a Windows Runtime Component doesn't declare a DllMain. This is not to say that it can't; it just picks up the dummy DllMain that the CRT defines (which basically turns off per-thread initialization and reports success).

Resources