简体   繁体   中英

Concerning the package name and RAW resources for Android App

I had a situation where I needed to create an alternate version of an app already written and compiled. I changed the package name; that's what I'm calling it, I'm referring to the "com.examplename.appname".

So the original name was something like: com.examplename.appname In the new app, I changed it to: com.examplename.appnamenew

So far so good. The app compiles and runs fine. But there is a video referenced in the app at that resource name: (I don't remember the syntax) uri = com.examplename.appname & "/Raw/video.mp4"

I didn't change that resource name because I figured it wouldn't matter if the resource is the same, because it compiles that RAW clip into the program.

It turns out, it does matter. If you have the OLD version and the NEW version on the same device at the same time, the NEW version runs fine (resource exists). But if you uninstall the OLD version, the NEW version cannot find the video. This is because the resource referenced in the compiled program is missing.

I changed the NEW version to point at the correct local resource, which solved the problem, of course.

But why is it that that happened at all? Why doesn't the video clip compile into the APK? Or does it, but still requires that resource pointer to be correct? More importantly, is this some sort of error?

Why doesn't the video clip compile into the APK?

It did, by your own admission ("I changed the NEW version to point at the correct local resource, which solved the problem, of course").

Or does it, but still requires that resource pointer to be correct?

If you have a Web site, located at http://www.durbnpoisn.com , and you move that Web site to http://www.durbnpoisn.org , all references to the original domain name will still work... until you take down the original domain name. Then those references break. Just because you change a domain name on your site does not somehow magically change all inbound URLs from the rest of the Internet.

In your case, you appear to have been using the android.resource:// Uri scheme. That stipulates a package. This is equivalent to the domain name in the URLs above. You changed the package name. References to the old package name will continue to work, though, so long as the old package was still around. Once you removed the old package, references to it would go away. Just because you change a package name does not somehow magically change all inbound references to the old package name from any place that has such a reference.

The same holds true for any place where you are hard-coding a package name. Hence, don't hard-code package names, but use other approaches (worst case: call getPackageName() on a handy Context , like your Activity ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM