Android Studio C++ inline compiler doesn't understand smart pointer upcasting - android

My Android Studio inline compiler shows me an error when passing an unique_ptr of a derived class to a function expecting an unique_ptr of a parent class. But the code compiles as I was expecting.
The error message from the code snippet above:
Parameter type mismatch: Class 'std::unique_ptr<B>' is not compatible with class 'std::unique_ptr<A>'
I guess is this a bug, related to Android Studio ? I was wondering if there was an options for this error checker, couldn't find anything
EDIT: Note that this code compiles with no errors from the compiler (the error I quoted is from the Android Studio's real time error checker). You can check the code here: https://ideone.com/xlUsKs

Related

Unordered_map declaration throws error with NDK (clang), works fine with gcc

I'm trying to run a C++ project on Android. The following statement appears in one of the source files (part of a big project).
std::unordered_map <int, std::shared_ptr<Frame>, std::hash<int>, std::equal_to<int>,
Eigen::aligned_allocator< std::pair<const int, std::shared_ptr<Frame> > > > idToKeyFrame;
The NDK build complains the following
sysroot/usr/include/c++/v1/unordered_map:1684:5: error: static_assert failed due to requirement 'is_same<value_type, typename allocator_type::value_type>::value' "Invalid allocator::value_type"
I cannot spot what part of declaration is incompatible. Please help in fixing this error.
cplusplus.com reference
Update
When I modify the allocator (as suggested in comment by Marc) to Eigen::aligned_allocator<std::pair<int, std::shared_ptr<Frame>>> The error message remains the same but line number changes
sysroot/usr/include/c++/v1/unordered_map:854:5: error: static_assert failed due to requirement 'is_same<value_type, typename allocator_type::value_type>::value' "Invalid allocator::value_type"
Update++
According to this answer :
libstdc++ does not static_assert, libstdc++ ignores the exact type of the allocator and rebinds it to the container's value type.
and
Clang/libc++ are not forgiving
Yet another Update
I have been able to go past the error by commenting out the line in the source for unordered_map. This is a resort for now (until I get a solution).

dynamic_cast doesn't work across module boundaries on clang

I am seeing a very strange failure that is very similar to the problem described in
dynamic_cast on llvm clang compiler failing: dynamic_cast returns nullptr when I am trying to downcast from base type to derived type, for an object of derived type. In my case though typeid actually shows the same dynamic type.
Below is the debug function that I use to verify run-time types. It takes a pointer of SrcType* and tries to dynamically cast it to pointer of DstType*. If conversion fails, i.e. the returned pointer is nullptr, it prints an error message. VERIFY() macro checks if condition is true:
template<typename DstType, typename SrcType>
void CheckDynamicType( SrcType *pSrcPtr )
{
VERIFY(dynamic_cast<DstType*> (pSrcPtr) != nullptr,
"Dynamic type cast failed. Src typeid: \'", typeid(*pSrcPtr).name(),
"\' Dst typeid: \'", typeid(DstType).name(), '\'');
}
And here is the output that I am getting:
Dynamic type cast failed. Src typeid: 'N8Diligent15RefCountersImplE' Dst typeid: 'N8Diligent15RefCountersImplE'
I am using clang compiler from Android ndk r16 toolchain. I am compiling with rtti flag. The same code works fine on gcc and msvc.
Another bit of information: the code also works fine if I build it with gnustl runtime (I am not sure how gnu stl works with clang, but anyway).
UPDATE
After spending few more hours looking into the issue I found out that dynamic_cast fails when it is used on the object created in another module.
From this
Using clang++, -fvisibility=hidden, and typeinfo, and type-erasure and this posts it looks like dynamic_cast should work if the class is labeled with __attribute__((visibility("default"))) so that typeid structures from two modules will be merged. This, however does not help either and I am still seeing the issue.
If you’re using the stock system compiler there’s a near 0 chance dynamic_cast of the compiler isn’t working. This is tested and used extensively in everything from system software up.

android data binding: how to get useful error messages

In android studio 2.1, the compile time error messages from xml mistakes are entirely non-helpful:
Error:(11, 41) error: package mypackage.databinding does not exist
Error:(15, 13) error: cannot find symbol class MyActivityBinding
The real error would usually be something like "there's no such attribute android:adapter", or "variable foo doesn't contain property bar" or something like that. But instead of actually showing such errors, it shows the above unhelpful ones, which only tell you that the bindings weren't generated because of some unknown error.
The way I use in Android Studio 4.0:
Select the top level Build: failed item on the Build Output panel
On the right part click Run with --stacktrace. When build is finished select the top Build: failed item again on the left panel. You'll get a databinding error description on the right panel:
In my case it's:
[databinding] {"msg":"Cannot find a getter for \u003ccom.google.android.material.slider.Slider app:value\u003e that accepts parameter type \u0027java.lang.Float\u0027\n\nIf a binding adapter provides the getter, check that the adapter is annotated correctly and that the parameter type matches.","file":"SliderDatabinding\src\main\res\layout\activity_main.xml","pos":[{"line0":14,"col0":8,"line1":21,"col1":41}]}
Clink on Toogle View, under the 'Build' icon will give you details logs
There's no easy way for now. In general, if you face such compilation error and error messages point at missing databinding classes it is usually either bad reference from layout (i.e. you try to access members classes you assigned do not expose - usually happens when you c&p layouts).
Even worse, when you use other code generating libraries (Icepick, Butterknife, etc) then the real culprit can be often in code completely unrelated to binding. So when something like this occur in my code, I usually check Gradle Console view and read it from the end up, ignoring all error messages related to databinding like "missing class" or "package does not exists"
One way of getting the proper error is to run gradle in a terminal with '--info', like:
gradle :app:build --info
That's not exactly integrated into AS, so I can't really accept that answer.

Printing by monodroid

I have a BIXOLON mobile printer, I can print by this device in windows mobile programs.
I want to print by this device in MONODOIRD applicaiton...
there is sdk, but the lib that use that sdk is java...
is any body know how can I print by this device in monodroid?!
Is your "lib" is a .jar file? If it is, bind it, which will make it accessible from C#.
after I read xamarin help about bindding jar file, I get some errors....
I listed in the end of this post...
I need this jar file compile completly...
Warning 1 missing class error was raised while reflecting com.bixolon.android.library.BxlService : android/hardware/usb/UsbManager
Warning 2 missing class error was raised while reflecting
com.bixolon.android.library.UsbLauncher : android/hardware/usb/UsbManager
Warning 3 For ConnectThread, could not find enclosing type 'BxlService'.
Warning 4 For ConnectThread, could not find enclosing type 'BxlService'.
Warning 5 For ConnectedThread, could not find enclosing type 'BxlService'.
Warning 6 For ConnectedThread, could not find enclosing type 'BxlService'.

Odd compiler error, Davlik error 1 from java.net.DatagramPacket.class

I suddenly started getting an unusual compiler error and is it making impossible to do any testing, I am running Eclipse with the plugin and compiling on the 2.1 version.
[2010-08-11 00:29:38 - PeriodTrackerv2]
trouble processing "java/net/DatagramPacket.class":
[2010-08-11 00:29:38 - PeriodTrackerv2]
Attempt to include a core class (java.* or javax.*) in something other
...
[2010-08-11 00:29:38 - PeriodTrackerv2] 1 error; aborting
[2010-08-11 00:29:38 - PeriodTrackerv2] Conversion to Dalvik format failed with error 1
I verified that this class does exist in the standard Android2.1 jar file, so I find it highly unusual a class in the actual base Jar file would be problematic. I am not using this class in any fashion in my program.
I updated to version 2.2 and still get same error, this completely baffles me and just appeared tonight after zero issues for months.
Any ideas on how to fix this?
Cheers,
Tom
Alright!
I reviewed the build path and somehow the Android.jar was added twice. Problem solved.

Categories

Resources