Android compile errors - indicate of c++ 11?

Hi cocos2dx-Team,

i recently updated my old cocos2dx (2017) project to the newest v3 version. Unfortunately I can’t get it to run or compile in Android. In my origin project I had boost included for a dependency injection library called Hypodermic. I had prebuild libraries for boost and tried to implement those with cmake and in the Android.mk file but every time I compiled the code he couldn’t find the boost headers. Now I dropped Hypodermic with boost, cause of the size and replaced it with cinject. A small independent framework which does the job. I modified the cmake and Android.mk accordingly but unfortunatlely I still got the following erros:

  ../../../../../../Classes/cinject.h:878:36: error: no matching function for call to 'make_component_type'
          container_->registrations_[make_component_type<TComponent>()]

../../../../../../Classes/cinject.h:1005:54: error: no matching function for call to 'make_component_type'
          contextPtr.reset(new InjectionContext(*this, make_component_type<cinject_unspecified_component>("Unspecified")));
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../../../../../../Classes/cinject.h:119:23: note: candidate function template not viable: no known conversion from 'const char [12]' to 'const std::string' (aka 'const basic_string<char, char_traits<char>, allocator<char> >') for 1st argument
  static component_type make_component_type(const std::string& customName = "")

...

The project is compiling and working on xcode. So from a quick google seach it looks like that is has something todo with c++11 or a newer version which cmake not compiling with?

Can you please help me here. I struggle with a working code for android now more than 4 days.

Thank you

1 Like

Android.mk isn’t utilized when you do the CMake build. Everything needs to be in the CMakeLists.txt file, which means all source references, all include paths etc…

You really should post the contents of your Android.mk and your CMakeLists.txt if you want more specific help.

Also, which version of the Android NDK are you using?

Sure. Sorry that I didn’t post it before.

Tried with NDK Versions:

  • 21.3.6528147
  • 16.1.4479499
  • r16b

Cocos2d Version: 3.17.2

CMakeLists.txt

#/****************************************************************************
# Copyright (c) 2013-2014 cocos2d-x.org
# Copyright (c) 2015-2017 Chukong Technologies Inc.
#
# http://www.cocos2d-x.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ****************************************************************************/

cmake_minimum_required(VERSION 3.6)

set(APP_NAME MyGame)

project(${APP_NAME})

set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cocos2d)
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)

include(CocosBuildSet)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)

# record sources, headers, resources...
set(GAME_SOURCE)
set(GAME_HEADER)

set(GAME_RES_FOLDER
    "${CMAKE_CURRENT_SOURCE_DIR}/Resources"
    )
if(APPLE OR WINDOWS)
    cocos_mark_multi_resources(common_res_files RES_TO "Resources" FOLDERS ${GAME_RES_FOLDER})
endif()

# add cross-platforms source files and header files 
#list(APPEND GAME_SOURCE
#     Classes/AppDelegate.cpp
#     Classes/HelloWorldScene.cpp
#     )
#list(APPEND GAME_HEADER
#     Classes/AppDelegate.h
#     Classes/HelloWorldScene.h
#     )

list(APPEND GAME_SOURCE
        Classes/AppDelegate.cpp
        .... <- all other cpp's
        )
list(APPEND GAME_HEADER
        Classes/cinject.h
        Classes/AppDelegate.h
        .... <- all other h's
        )


if(ANDROID)
    # change APP_NAME to the share library name for Android, it's value depend on AndroidManifest.xml
    set(APP_NAME MyGame)
    list(APPEND GAME_SOURCE
         proj.android/app/jni/hellocpp/main.cpp
         )
elseif(LINUX)
    list(APPEND GAME_SOURCE
         proj.linux/main.cpp
         )
elseif(WINDOWS)
    list(APPEND GAME_HEADER
         proj.win32/main.h
         proj.win32/resource.h
         )
    list(APPEND GAME_SOURCE
         proj.win32/main.cpp
         proj.win32/game.rc
         ${common_res_files}
         )
elseif(APPLE)
    if(IOS)
        list(APPEND GAME_HEADER
             proj.ios_mac/ios/AppController.h
             proj.ios_mac/ios/RootViewController.h
             )
        set(APP_UI_RES
            proj.ios_mac/ios/LaunchScreen.storyboard
            proj.ios_mac/ios/LaunchScreenBackground.png
            proj.ios_mac/ios/Images.xcassets
            )
        list(APPEND GAME_SOURCE
             proj.ios_mac/ios/main.m
             proj.ios_mac/ios/AppController.mm
             proj.ios_mac/ios/RootViewController.mm
             proj.ios_mac/ios/Prefix.pch
             ${APP_UI_RES}
             )
    elseif(MACOSX)
        set(APP_UI_RES
            proj.ios_mac/mac/Icon.icns
            proj.ios_mac/mac/Info.plist
            )
        list(APPEND GAME_SOURCE
             proj.ios_mac/mac/main.cpp
             proj.ios_mac/mac/Prefix.pch
             ${APP_UI_RES}
             )
    endif()
    list(APPEND GAME_SOURCE ${common_res_files})
endif()

# mark app complie info and libs info
set(all_code_files
    ${GAME_HEADER}
    ${GAME_SOURCE}
    )
if(NOT ANDROID)
    add_executable(${APP_NAME} ${all_code_files})
else()
    add_library(${APP_NAME} SHARED ${all_code_files})
    add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos/platform/android ${ENGINE_BINARY_PATH}/cocos/platform)
    target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive)
endif()

target_link_libraries(${APP_NAME} cocos2d)
target_include_directories(${APP_NAME}
        PRIVATE Classes
        PRIVATE ${COCOS2DX_ROOT_PATH}/cocos/audio/include/
)

# mark app resources
setup_cocos_app_config(${APP_NAME})
if(APPLE)
    set_target_properties(${APP_NAME} PROPERTIES RESOURCE "${APP_UI_RES}")
    if(MACOSX)
        set_target_properties(${APP_NAME} PROPERTIES
                              MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/mac/Info.plist"
                              )
    elseif(IOS)
        cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
        set_xcode_property(${APP_NAME} ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")
        set_xcode_property(${APP_NAME} DEVELOPMENT_TEAM "")
        set_xcode_property(${APP_NAME} CODE_SIGN_IDENTITY "iPhone Developer")
    endif()
elseif(WINDOWS)
    cocos_copy_target_dll(${APP_NAME})
endif()

if(LINUX OR WINDOWS)
    set(APP_RES_DIR "$<TARGET_FILE_DIR:${APP_NAME}>/Resources")
    cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
endif()

Application.mk

APP_STL := c++_static

APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char -Wno-extern-c-compat
APP_LDFLAGS := -latomic

APP_ABI := armeabi-v7a
APP_SHORT_COMMANDS := true


ifeq ($(NDK_DEBUG),1)
  APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
  APP_OPTIM := debug
else
  APP_CPPFLAGS += -DNDEBUG
  APP_OPTIM := release
endif

Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := MyGame_shared

LOCAL_MODULE_FILENAME := libMyGame

LOCAL_SRC_FILES := $(LOCAL_PATH)/hellocpp/main.cpp \
                   $(LOCAL_PATH)/../../../Classes/AppDelegate.cpp \
                   $(LOCAL_PATH)/../../../Classes/HelloWorldScene.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END


LOCAL_STATIC_LIBRARIES := cc_static

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

$(call import-module, cocos)

# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END

Tried some configurations in Android.mk and Application.mk like:

NDK_TOOLCHAIN_VERSION := clang
LOCAL_CPPFLAGS += -std=c++11

Or in the CMake:

set(DCMAKE_ANDROID_STL_TYPE, c++_static)
set(DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION, clang)
set(DANDROID_STL, c++_static)

I’m not that familiar with CMake. So I just found from the cinject library that they use from C++ 11 features like variadic templates, shared_ptr and type traits and those seems to break it. So I tried so search for it. I also tried some other libraries but those gave similiar errors.

Is there anything what I’m missing? Is there a flag missing?

Also I have one other question related to CMake. Is the order of the files on:

list(APPEND GAME_SOURCE
        )
list(APPEND GAME_HEADER
        )

Important?

Thank you # R101 for your quick help. Maybe you could help me now with a more detailed with in my problem.

Add these lines after the include(CocosBuildSet) in your CMakeLists.txt:

# Make sure this and any other setting is done AFTER the "include(CocosBuildSet)", since it
# sets the same items, and overrides our settings
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

You can change the 14 to 11 if you just want C++11. Also, I’m using C++17, and it’s perfectly fine on Android, so 11 should work.

For example:

include(CocosBuildSet)
add_subdirectory(
    ${COCOS2DX_ROOT_PATH}/cocos 
    ${ENGINE_BINARY_PATH}/cocos/core
)

# Make sure this and any other setting is done AFTER the "include(CocosBuildSet)", since it
# sets the same items, and overrides our settings
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# record sources, headers, resources...
set(GAME_SOURCE)
set(GAME_HEADER)

... rest of the file

I don’t know what these are for, as I don’t use them in any of my project CMakeLists.txt files, so just comment them out or delete them for now:

set(DCMAKE_ANDROID_STL_TYPE, c++_static)
set(DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION, clang)
set(DANDROID_STL, c++_static)

In your /proj.android/gradle.properties file, make sure you have this set:

# Android SDK version that will be used as the compile project
PROP_COMPILE_SDK_VERSION=28

# Android SDK version that will be used as the earliest version of android this application can run on
PROP_MIN_SDK_VERSION=16

# Android SDK version that will be used as the latest version of android this application has been tested on
PROP_TARGET_SDK_VERSION=28

# android native code build type
# none, native code will never be compiled.
# cmake, native code will be compiled by CMakeLists.txt
# ndk-build, native code will be compiled by Android.mk
PROP_BUILD_TYPE=cmake

Now if you open up /proj.android/app/build.gradle you’ll see this:

        externalNativeBuild {
            if (PROP_BUILD_TYPE == 'ndk-build') {
                ndkBuild {
                    targets 'MyGame'
                    arguments 'NDK_TOOLCHAIN_VERSION=clang'
                    arguments '-j' + Runtime.runtime.availableProcessors()

                    def module_paths = [project.file("../../cocos2d").absolutePath,
                                        project.file("../../cocos2d/cocos").absolutePath,
                                        project.file("../../cocos2d/external").absolutePath]
                    if (OperatingSystem.current().isWindows()) {
                        module_paths = module_paths.collect {it.replaceAll('\\\\', '/')}
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(";")
                    }
                    else {
                        arguments 'NDK_MODULE_PATH=' + module_paths.join(':')
                    }
                }
            }
            else if (PROP_BUILD_TYPE == 'cmake') {
                cmake {
                    targets 'MyGame'
                    arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE"
                    cppFlags "-frtti -fexceptions -fsigned-char"
                    version "3.10.2"
                }
            }
        }

Add version "3.10.2" in the cmake section, as you see above. Make sure you have it installed via the Android Studio SDK manager:

You may need to set the ndkVersion field in that same build.gradle file to the specific version you’re using. For example, using version 21.3.6528147:

...
android {
    compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
    ndkVersion "21.3.6528147"

    defaultConfig {
...

As long as Android Studio can find the NDK folder with that version, it’ll work.

Anyhow, do the changes mentioned at the top of this post, and see how you go. If you’re going to use CMake (and I strongly suggest that you do), then you can ignore the Android.mk and Application.mk files, since they are not used in the CMake builds.

#R101 Thanks again for your answer. I added your suggested code but unfortunately it didn’t work. Now I started a new sample project to get the problem step by step closer. It seems that the problem comes when I include the header from cinject in any other new created header file. Its compiling successfully when I include the cinject in the AppDelegate. What’s make here the difference between those two? Again in Xcode it doesn’t matter, everything works. Does the structure of the cinject header breaks something? Would it be helpful when I upload the sample project? I really wanted to get this dependency injection to work. For projects in future and also for the understanding, why it was not working. Cinject looks great for what I want.

Thanks also for the hint that only cmake matters. That helped a lot :wink:

Maybe you know what’s the root of the problem.

Yes it would be. If you’re uploading it as an attachment in a forum post, then zip it up without the “cocos2d” folder, just to keep the size of the file small.

I just tested it out, and it compiles fine. Here’s what I did:
1 - Copied the cinject.h file into the /Classes/ folder, then included it in HelloWorldScene.h with #include "cinject.h"
2 - Copied over the class definitions from cinject/src/sample/cinject_test_app.cpp into the HelloWorldScene.h.
3 - Copied over the contents of main() in cinject/src/sample/cinject_test_app.cpp to the HelloWorldScene.cpp init() method.
4 - Add using namespace cinject; the top of the HelloWorldScene.cpp.

Compiled in Visual Strudio 2019 and Android Studio without errors.

Sure. Here you go project:

This is how I would implement the dependency injection. I would create a new class which make all the resolving, called Assembly. It seems the problem comes after I include the cinject into the Assembly.h. For the HelloWorldScene it also works for me. So maybe I have a problem with the structure. Maybe you could help me now better with the project upload. As I said before it works in XCode but not while compiling in Android Studio.

Those are the exceptions:

... onstructorFactory<Test, void> >::value' "Can't construct object in make_shared"
      static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" );
      ^              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/memory:4581:29: note: in instantiation of function template specialization 'std::__ndk1::shared_ptr<cinject::InstanceStorage<Test, cinject::ConstructorFactory<Test, void> > >::make_shared<cinject::ConstructorFactory<Test, void> >' requested here
      return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
                              ^
  ../../../../../../Classes/cinject.h:810:37: note: in instantiation of function template specialization 'std::__ndk1::make_shared<cinject::InstanceStorage<Test, cinject::ConstructorFactory<Test, void> >, cinject::ConstructorFactory<Test, void> >' requested here
          auto instanceStorage = std::make_shared<InstanceStorageType>(ConstructorFactory<TImplementation>());
                                      ^
  ../../../../../../Classes/Assembly.cpp:18:29: note: in instantiation of function template specialization 'cinject::ComponentBuilderBase<ITest>::to<Test>' requested here
      container.bind<ITest>().to<Test>();
                              ^
  In file included from ../../../../../../Classes/Assembly.cpp:8:
  In file included from ../../../../../../Classes/Assembly.hpp:11:
  In file included from ../../../../../../Classes/cinject.h:4:
  In file included from /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/vector:274:
  In file included from /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/__bit_reference:15:
  In file included from /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/algorithm:643:
  /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/memory:4205:28: error: assigning to 'std::__ndk1::__shared_weak_count *' from incompatible type 'std::__ndk1::unique_ptr<std::__ndk1::__shared_ptr_emplace<cinject::InstanceStorage<Test, cinject::ConstructorFactory<Test, void> >, std::__ndk1::allocator<cinject::InstanceStorage<Test, cinject::ConstructorFactory<Test, void> > > >, std::__ndk1::__allocator_destructor<std::__ndk1::allocator<std::__ndk1::__shared_ptr_emplace<cinject::InstanceStorage<Test, cinject::ConstructorFactory<Test, void> >, std::__ndk1::allocator<cinject::InstanceStorage<Test, cinject::ConstructorFactory<Test, void> > > > > > >::pointer' (aka 'std::__ndk1::__shared_ptr_emplace<cinject::InstanceStorage<Test, cinject::ConstructorFactory<Test, void> >, std::__ndk1::allocator<cinject::InstanceStorage<Test, cinject::ConstructorFactory<Test, void> > > > *')
      __r.__cntrl_ = __hold2.release();
                     ~~~~~~~~^~~~~~~~~
  In file included from ../../../../../../Classes/Assembly.cpp:8:
  In file included from ../../../../../../Classes/Assembly.hpp:11:
  ../../../../../../Classes/cinject.h:878:36: error: no matching function for call to 'make_component_type'
          container_->registrations_[make_component_type<TComponent>()]
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../../../../../../Classes/cinject.h:870:9: note: in instantiation of function template specialization 'cinject::ComponentBuilderBase<ITest>::addRegistration<Test, cinject::InstanceStorage<Test, cinject::ConstructorFactory<Test, void> >, ITest>' requested here
          addRegistration<TImplementation, TInstanceStorage, TComponent>(instanceStorage);
          ^
  ../../../../../../Classes/cinject.h:812:9: note: in instantiation of function template specialization 'cinject::ComponentBuilderBase<ITest>::registerType<Test, cinject::InstanceStorage<Test, cinject::ConstructorFactory<Test, void> >, ITest>' requested here
          registerType<TImplementation, InstanceStorageType, TComponents...>(instanceStorage);
          ^
  ../../../../../../Classes/Assembly.cpp:18:29: note: in instantiation of function template specialization 'cinject::ComponentBuilderBase<ITest>::to<Test>' requested here
      container.bind<ITest>().to<Test>();
                              ^
  ../../../../../../Classes/cinject.h:119:23: note: candidate function template not viable: requires single argument 'customName', but no arguments were provided
  static component_type make_component_type(const std::string& customName = "")
                        ^
  In file included from ../../../../../../Classes/Assembly.cpp:8:
  In file included from ../../../../../../Classes/Assembly.hpp:11:
  In file included from ../../../../../../Classes/cinject.h:7:
  In file included from /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/unordered_map:409:
  /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/__hash_table:2142:29: error: cannot initialize object parameter of type 'std::__ndk1::__hash_node_base<std::__ndk1::__hash_node<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, void *> *>' with an expression of type 'std::__ndk1::__hash_node<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, void *>'
              __pn->__next_ = __h.get()->__ptr();
                              ^~~~~~~~~
  /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/__hash_table:1163:16: note: in instantiation of function template specialization 'std::__ndk1::__hash_table<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, std::__ndk1::__unordered_map_hasher<cinject::component_type, std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, cinject::component_type_hash, true>, std::__ndk1::__unordered_map_equal<cinject::component_type, std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, std::__ndk1::equal_to<cinject::component_type>, true>, std::__ndk1::allocator<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > > > >::__emplace_unique_key_args<cinject::component_type, const std::__ndk1::pair<const cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > > &>' requested here
          return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x);
                 ^
  /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/unordered_map:1624:18: note: in instantiation of member function 'std::__ndk1::__hash_table<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, std::__ndk1::__unordered_map_hasher<cinject::component_type, std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, cinject::component_type_hash, true>, std::__ndk1::__unordered_map_equal<cinject::component_type, std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, std::__ndk1::equal_to<cinject::component_type>, true>, std::__ndk1::allocator<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > > > >::__insert_unique' requested here
          __table_.__insert_unique(*__first);
                   ^
  /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/unordered_map:1506:5: note: in instantiation of function template specialization 'std::__ndk1::unordered_map<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > >, cinject::component_type_hash, std::__ndk1::equal_to<cinject::component_type>, std::__ndk1::allocator<std::__ndk1::pair<const cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > > > >::insert<std::__ndk1::__hash_map_const_iterator<std::__ndk1::__hash_const_iterator<std::__ndk1::__hash_node<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, void *> *> > >' requested here
      insert(__u.begin(), __u.end());
      ^
  ../../../../../../Classes/cinject.h:346:7: note: in instantiation of member function 'std::__ndk1::unordered_map<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > >, cinject::component_type_hash, std::__ndk1::equal_to<cinject::component_type>, std::__ndk1::allocator<std::__ndk1::pair<const cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > > > >::unordered_map' requested here
  class Container
        ^
  /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/memory:2258:9: note: in instantiation of function template specialization 'std::__ndk1::__compressed_pair_elem<cinject::Container, 1, false>::__compressed_pair_elem<cinject::Container &, 0>' requested here
          _Base2(__pc, _VSTD::move(__second_args),
          ^
  /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/memory:3543:16: note: in instantiation of function template specialization 'std::__ndk1::__compressed_pair<std::__ndk1::allocator<cinject::Container>, cinject::Container>::__compressed_pair<std::__ndk1::allocator<cinject::Container> &, cinject::Container &>' requested here
              :  __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
                 ^
  /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/memory:4202:26: note: in instantiation of function template specialization 'std::__ndk1::__shared_ptr_emplace<cinject::Container, std::__ndk1::allocator<cinject::Container> >::__shared_ptr_emplace<cinject::Container &>' requested here
      ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
                           ^
  /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/memory:4581:29: note: in instantiation of function template specialization 'std::__ndk1::shared_ptr<cinject::Container>::make_shared<cinject::Container &>' requested here
      return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
                              ^
  ../../../../../../Classes/Assembly.cpp:20:17: note: in instantiation of function template specialization 'std::__ndk1::make_shared<cinject::Container, cinject::Container &>' requested here
      return std::make_shared<cinject::Container>(container);
                  ^
  In file included from ../../../../../../Classes/Assembly.cpp:8:
  In file included from ../../../../../../Classes/Assembly.hpp:11:
  In file included from ../../../../../../Classes/cinject.h:7:
  In file included from /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/unordered_map:409:
  /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/__hash_table:2147:23: error: cannot initialize object parameter of type 'std::__ndk1::__hash_node_base<std::__ndk1::__hash_node<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, void *> *>' with an expression of type 'std::__ndk1::__hash_node<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, void *>'
                      = __h.get()->__ptr();
                        ^~~~~~~~~
  /Users/stephan/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/__hash_table:2154:16: error: static_cast from 'std::__ndk1::unique_ptr<std::__ndk1::__hash_node<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, void *>, std::__ndk1::__hash_node_destructor<std::__ndk1::allocator<std::__ndk1::__hash_node<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, void *> > > >::pointer' (aka 'std::__ndk1::__hash_node<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, void *> *') to 'std::__ndk1::__hash_table<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, std::__ndk1::__unordered_map_hasher<cinject::component_type, std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, cinject::component_type_hash, true>, std::__ndk1::__unordered_map_equal<cinject::component_type, std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, std::__ndk1::equal_to<cinject::component_type>, true>, std::__ndk1::allocator<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > > > >::__next_pointer' (aka 'std::__ndk1::__hash_node_base<std::__ndk1::__hash_node<std::__ndk1::__hash_value_type<cinject::component_type, std::__ndk1::vector<std::__ndk1::shared_ptr<cinject::IInstanceRetriever>, std::__ndk1::allocator<std::__ndk1::shared_ptr<cinject::IInstanceRetriever> > > >, void *> *> *'), which are not related by inheritance, is not allowed
          __nd = static_cast<__next_pointer>(__h.release());
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14 errors generated.

Also worth to mention. When I move the classes, the inteface and the function body of Assembly::make to the AppDelegate everything works. So there should be no issue with using cinject.

IDEs:

Xcode 12
Android Studio 4.1

Thanks for your help.

The cinject.h is the culprit.

Add these two required include statements to the cinject.h:

#include <stdexcept>
#include <string>

The only reason it compiled when cinject.h was included in AppDelegate.h is because the required headers were already included earlier in the build process.

Thanks! That was the solution. How did you find that? Unfortunately I got now another issue where I just can’t find the root of… but this is in another topic

Both Android Studio and Visual Studio showed me the same compilation errors regarding unknown types. The Visual Studio IDE also showed the errors in the actual cinject.h file when viewing it (missing references to std::log_error etc).

Crazy. Ok maybe I will switch then to Android Studio when Xcode could run this without any exception.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.