android - Where to put an asset file to be accessible for an application? -
android - Where to put an asset file to be accessible for an application? -
got updates recently, i.e. moved eclipse android studio , started using gradle. besides, target api got updated 16 20 , things not working used to.
i started refactoring part of application responsible fetching database file. logcat reports no assets in application/app/assets directory, (assets @ same level src dir), although dbfile.sqlite there.
as checked, have next things among assets:
assetmanager assetmanager = getassets(); string[] assetfile = assetmanager.list(""); (int = 0; < assetfile.length; i++) { log.d(ptag, "assets found [" + + "]: " + assetfile[i]); } output:
d/mainactivity﹕ assets found [0]: images d/mainactivity﹕ assets found [1]: sounds d/mainactivity﹕ assets found [2]: webkit nothing databases. know set database file , how provide application it?
in classic android studio project, assets go in assets/ directory in main sourceset, or in sourceset if appropriate. so, if android studio project has app in app/ module of project, assets go in app/src/main/assets/. blended in assets other sourcesets in project, plus contributed android library projects, , bundled apk.
here sample app uses sqliteassethelper packaging database app. has database in databases/ directory within app/src/main/assets/. resulting apk has database right expect:
sqliteassethelper able pick asset expect.
note project uses appcompat-v7 (and hence support-v4 through transitive dependency).
now, can have assets located elsewhere if prefer, need teach gradle find them. example, my cwac-richtextutils project shares assets between richtextutils library's tests (in androidtest) , separate demo module. rather have 2 copies of assets, have 1 @ project level, , point each module's configuration assets in build.gradle files:
sourcesets { main { assets.srcdirs = ['../testassets'] } } android
Comments
Post a Comment