Building a library project

  • Created a library project with some reusable code from my project.
  • The library code used a json file from the data folder of my project.
  • To read resource folder files, we need context. Thus, when initializing an instance of a library project from a production project, I pass on its context.
  • Now that all the code is working fine, I want to move the json file from my production project to the library project, because this file is independent of the library and vice versa.
  • After moving the file to the library project when reading the json file, it throws an exception not found in the file.
  • Perhaps this is due to the fact that the context that I pass to the library project refers to my production project, while the file is now in the library resource of the library project.
  • The goal of the library is to win if the json file is not packaged with it.
  • How to get context so that I can read the asset file from the library project.?
+5
source share
1 answer

From Android docs: http://developer.android.com/tools/projects/index.html

Library modules cannot include source resources

The tools do not support the use of source asset files (stored in the assets / directory) in the library module. Any resource resources used by the application must be stored in the assets / assets directory of the application module itself. However, resource files stored in the res / directory are supported.

And here is how you can read JSON from the res / raw folder: JSON Parsing in android - from the resources folder

Other workarounds:

reference to the object in the library project

+5
source

Source: https://habr.com/ru/post/1208877/


All Articles