-3

I want to link to different files. i.e. Link a .java file and a .txt file such that when i made changes the .java file automatically the stuff within the .java file is copied on the .txt file.

The main objective of mine is to display the source code of my android application to the user. I understand that the .java files get compiled and only the compiled versions stick to the final app.

pravchuk
  • 903
  • 10
  • 14

1 Answers1

1

I've never tried this, but this in theory should work. Make use of "hard links" such that your source code is also a raw resource.

cd project/res    (cd into your "res" directory)
mkdir raw         (make a "raw" directory if it doesn't already exist)
cd raw
ln ../../src/com/domain/appname/MainActivity.java mainactivity   (create a hard link on Unix/Mac)

On Windows, the last line above is replaced with:

mklink /H ../../src/com/domain/appname/MainActivity.java mainactivity

Now MainActivity.java is a resource file in your code. Changes in the original MainActivity.java will be reflected as the mainactivity raw resource. But because resources in raw can't have capital letters or dots, it must just be linked as "mainactivity". It will have a resource id R.raw.mainactivity.

Repeat the above steps for all the other source files you may have.

You can read how to load your text from a raw resource by following the example question as an answer here.

Community
  • 1
  • 1
selbie
  • 100,020
  • 15
  • 103
  • 173
  • If you ever copy your project folder or use a source repository tool such a git, the hard link between the resource file name and the original source name will likely be lost as files get moved around and copied. – selbie Aug 25 '14 at 01:51