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.