gordonwd
gordonwd

Reputation: 4587

Asset file not in build using Android Studio 3.0.1

My app has a sample data file of a private type that has been included with it since the app was originally built for Android 2.3. The code that references it is like so:

Resources res = mCtx.getResources();
AssetManager assMan = res.getAssets();

try {
    is = assMan.open(DB_SAMPLE);

    // stuff that copies to destination...
}
catch (IOException e) {
    stat = false;
}

What happens with builds from Android Studio 3.0.1 is that the assMan.open method jumps to the exception handler with a "File not found" error. The asset folder and file are definitely there, and based on a similar question I deleted and recreated the asset folder and copied the file back into it. In the Project view pane the "assets" folder is directly under "main" and has the same icon as the "res" folder. The project now targets SDK 26, but this failure occurs also on all older Android builds that I've tried.

Is there something I have to do to specifically get my file to be recognized, or has something else changed? Or it is just a bug?

Question closed: Neglected to try doing a Clean Project, thinking that Rebuild All would include doing this. The assets folder is now in the APK and all is working.

Upvotes: 3

Views: 1152

Answers (2)

Juan Torres
Juan Torres

Reputation: 77

As stated above sometimes after several builds using AS(Android studio) ,some asset ressources such as images were partially copied in apk, then a simple Clean Project before Build APKs should fix this behavior as i can confirm from my situation enter image description here

As you can see, after strugling tryng to find out why i got IO exception everytime i run the application, i thought it was the code but it happens files were not present in the apk due to build process.

java.io.FileNotFoundException: V_Line.png 05-06 14:58:22.256 E/PTL_EmailSender( 3344): at android.content.res.AssetManager.openAsset(Native Method) 05-06 14:58:22.256 E/PTL_EmailSender( 3344): at android.content.res.AssetManager.open(AssetManager.java:374) 05-06 14:58:22.256 E/PTL_EmailSender( 3344): at android.content.res.AssetManager.open(AssetManager.java:348) 05-06 14:58:22.256 E/PTL_EmailSender( 3344): at com.pixeemedical.portal.email.EmailSender.sendEmail(EmailSender.java:99)

missings assets inside apk:

enter image description here

Be Aware AS 3.4.1 is not that robust when handling ressources data of build.

Upvotes: 0

gordonwd
gordonwd

Reputation: 4587

Lesson learned not for the first time: When in doubt, always do a Clean Project before rebuilding a release. The "assets" folder is back in the APK where it belongs.

Upvotes: 4

Related Questions