0

I would like to add an external 'C' library, and by external I mean that is in a completely different folder (not even where I store the android studio projects).

I tried to follow this answer: Android Studio: Adding a library outside of the project root , but I do not know why this is not working (probably because this example is about two projects being in the same folder).

This is my code in gradle.settings, but it keeps saying that it cannot find the library.

include ':ItemData'
project(':ItemData').projectDir = new File(settingsDir, '../Sandbox/Software/RABBIT/UVTrolley/Ver01.6/ItemData')

Just in case you may ask the "../" should be the C: and this is my code in build.gradle(app)

compile project(':ItemData')

and finally this is what I got in my Cmake

add_library(ItemData SHARED
 ${SRC_DIR}../Sandbox/Software/RABBIT/UVTrolley/Ver01.6/ItemData/itemdata.c)
target_link_libraries(ItemData)

So what am I doing wrong?

Here the error message:

Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve project :ItemData.
     Required by:
         project :app
      > No matching configuration of project :ItemData was found. The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' but:
          - None of the consumable configurations have attributes.
  • Hi can you post the error message too ? – CodeWithVikas Jun 14 '21 at 11:47
  • Thanks for asking. Here the error message: Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'. > Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'. > Could not resolve project :ItemData. Required by: project :app > No matching configuration of project :ItemData was found. The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' but: - None of the consumable configurations have attributes. – Alessandro Cinque Jun 14 '21 at 12:19
  • I assume it like you want to add a c library into your android project. Please have a look at https://stackoverflow.com/a/67969634/5165107 hope it will help. – CodeWithVikas Jun 14 '21 at 15:06
  • Not really because the library I need it is and HAS to be outside the android/project folder. It is a "home-made" library which could change many times, so for me to do not do copy and paste every time I change it I need the library to stay where it is. But thanks anyway for your help. – Alessandro Cinque Jun 15 '21 at 11:22

1 Answers1

0

I have solved it!

By using this website as a documentation: https://medium.com/@sourav.bh/build-a-native-android-library-or-module-using-ndk-and-cmake-71988b00b5dd

I realised that the ${SRC_DIR} means "search in this folder" which is exactly what I don't want!

So disregard what I did in gradle.settings and gradle.build (that's garbage) and in the cMake just write the entire path

add_library(ItemData SHARED C:/Sandbox/Software/RABBIT/UVTrolley/Ver01.6/ItemData/itemdata.c) and then,to make appear on the side bar of your project

target_include_directories(ItemData PRIVATEC:/Sandbox/Software/LIBRARY/ItemData)

target_link_libraries(ItemData)

I also think that you could link a file in the network if you write //YourNetworkName/.. instead of C:/ but I haven't tested it yet.