Extract assets from Android Lib Project

I have two separate projects, plus and a free version. Both projects use a significant amount of common code, so I'm trying to integrate everything that is shared into an Android library project.

One of the common resources is the database in which I was sitting in FreeProject / assests / database.db. This file is shared between both projects, and I would like to move it to LibraryProject / assets / database.db.

In the code, I moved the database to the database folder with the following:

String dbLocation = "/data/data/" + myContext.getPackageName() + "/databases/" + DBNAME; //Reading the asset and writing it to the database folder. InputStream myInput = myContext.getAssets().open("database.db"); OutputStream myOutput = new FileOutputStream(dbLocation); byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer)) > 0) { myOutput.write(buffer, 0, length); } myOutput.flush(); myOutput.close(); myInput.close(); 

So my question is: how can I call getAssets () to get the AssetManager for the library project? Or is there another way I could / should have done this?

+2
source share
1 answer

From docs :

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

Could you use res / raw and openRawResource () ?

+2
source

All Articles