Updated String.xml not getting deployed

We are seeing an issue on multiple environments where the Strings.xml values are not getting updated when we deploy/debug to both an emulator or physical device. The C# code is getting updated. It seems like the old Strings.xml is cached somewhere? If we completely uninstall our app from the device before deploy/debug then we get the correct values. Any ideas?

Tried with 4.2.3, 4.2.6 and 4.2.8 beta.

Thanks

Posts

  • Hi,

    Try changing some C# code (go into an activity and enter a line break), then redeploy. Sometimes, it doesn't copy and files if no code has changed I think.

  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    We are seeing an issue on multiple environments where the Strings.xml values are not getting updated when we deploy/debug to both an emulator or physical device.

    Sounds like a timestamp problem.

    It seems like the old Strings.xml is cached somewhere?

    Yes. Android Resources are processed and copied into obj\Debug\res; this copy is what is used to build the .apk. This process should be driven by file timestamps -- when you update Resources\Values\Strings.xml, it should be copied into obj\Debug\res\values\strings.xml and cause the .apk to be rebuilt.

    That this isn't happening suggests that the timestamp on your updated Strings.xml may not be correct, or something is going wrong in the build system. Diagnostic build output may be helpful.

    Try changing some C# code (go into an activity and enter a line break), then redeploy.

    This shouldn't help with Debug builds. By default, Fast Deployment is enabled, and Fast Deployment works by not embedding assemblies into the .apk. Instead, they're copied directly to the device. This allows us to avoid rebuild and redeploying the .apk, which speeds up the debug turnaround cycle.

    Ideally, the only time modifying C# code will result in redeploying the .apk is when you do a change that changes the Android Callable Wrappers, e.g. by adding a new Java.Lang.Object subclass or overrideing a new method.

  • OldRedthOldRedth USMember, Insider ✭✭✭

    I believe I've seen this behavior on windows + MonoDevelop as well. I'll keep an eye out next time I'm working with that too.

  • RydawgRydawg USBeta

    Thanks for the suggestions Jon. I compared the Strings.xml to the copy in the obj folder and it does appear to be getting updated properly. I attached the Diagnostic Output for a rebuild.

    Thanks for your help.

  • RydawgRydawg USBeta

    Let's try this again... attaching the correct file this time.

  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    Conjecture: Are you building this within a DropBox directory? I have seen circumstances where things weren't rebuilt when expected because DropBox was busy modifying timestamps, screwing everything up.

    Did the rebuild work? I'm assuming it did, as I see lots of file deletes in there.

    What we need is the build output for a "bad" build: update Strings.xml, Build (not Rebuild), and capture the log output.

    This may require exiting Visual Studio, editing Strings.xml in e.g. WordPad, and invoking msbuild /v:diag > log.txt from the command line, as Visual Studio may update things in the background, preventing you from seeing the desired output. On the flip side, this may cause things to work...

    Key questions: did the _UpdateAndroidResgen target get executed? Was the Aapt task executed? If not, why not?

  • RydawgRydawg USBeta

    Conjecture: Are you building this within a DropBox directory? I have seen circumstances where things weren't rebuilt when expected because DropBox was busy modifying timestamps, screwing everything up.

    No, not a dropbox folder.

    Did the rebuild work? I'm assuming it did, as I see lots of file deletes in there. What we need is the build output for a "bad" build: update Strings.xml, Build (not Rebuild), and capture the log output.

    No, the rebuild doesn't work either.

    This may require exiting Visual Studio, editing Strings.xml in e.g. WordPad, and invoking msbuild /v:diag > log.txt from the command line, as Visual Studio may update things in the background, preventing you from seeing the desired output. On the flip side, this may cause things to work...

    I'll try this.

    Key questions: did the _UpdateAndroidResgen target get executed? Was the Aapt task executed? If not, why not?

    They both appear to be executed.

  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    I do believe I misread an earlier message. @Rydawg wrote:

    I compared the Strings.xml to the copy in the obj folder and it does appear to be getting updated properly.

    So Strings.xml is getting updated properly. The problem:

    Strings.xml values are not getting updated when we deploy/debug to both an emulator or physical device.

    Rebuild output will not help here, because Rebuild doesn't rebuild the .apk,
    nor does it redeploy it to the device. Check OutputRebuild.txt: there is no
    invocation of the SignAndroidPackage, PackageForAndroid, or _Sign
    targets. (This is also By Design; Build does not rebuild the .apk,
    because building the .apk is slow, and developers frequently Build their
    project to make sure that code compiles. Creating the .apk during Build
    resulted in a slow, miserable experience.)

    What we need to know is why the .apk isn't rebuilt when you Debug or
    Deploy your app.

    I don't know if Visual Studio will generate MSBuild logs when you Debug your
    application.

    What you may instead want to try is to open a VS2012 x64 Native Tools Command Prompt and execute the following command from your project directory

    msbuild /t:Install LM.MDM.AndroidClient.csproj /v:diag > log.txt
    

    Then provide the logs. In particular, I want to know if the _Sign target is
    getting invoked and the .apk is being updated. (This all assumes that
    Strings.xml has been updated since the last time the .apk was rebuilt...)

  • RydawgRydawg USBeta

    Here is the log from the msbuild command.

    log.txt 248.7K
  • RydawgRydawg USBeta

    OK, we found a way to force it to update but it is kind of a pain. First we have to remove the active admin for our app (DevicePolicyManager.RemoveActiveAdmin) and then we have to force stop the app from the applications menu. After doing that if we change strings.xml and re-deploy then the UI gets updated properly.

  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    Unfortunately, I'm still at a loss for why things aren't working; they should be:

    Building target "_GenerateAndroidResourceDir" completely.
    ...
      Copying file from "Resources\Values\Strings.xml" to "D:\Working\8.0\MDM_Team\Features\MDM\Client\Android\LM.MDM.AndroidClient\obj\Debug\res\values\strings.xml". (TaskId:7)
    ...
    Building target "_UpdateAndroidResgen" completely.
    Input file "D:\Working\8.0\MDM_Team\Features\MDM\Client\Android\LM.MDM.AndroidClient\obj\Debug\res\values\strings.xml" is newer than output file "obj\Debug\R.cs.flag".
    ...
    Task "Aapt" (TaskId:113)
    ...
    Building target "_Sign" completely.
    ...
    Target "_Upload: (TargetId:90)" in file "C:\Program Files (x86)\MSBuild\Novell\Novell.MonoDroid.Common.targets" from project "D:\Working\8.0\MDM_Team\Features\MDM\Client\Android\LM.MDM.AndroidClient\LM.MDM.AndroidClient.csproj" (target "Install" depends on it):
    ...
    

    It certainly looks like it's copying your updated Resources\Values\Strings.xml into obj\Debug\res\values\strings.xml, then rebuilding, signing, and installing the .apk...

  • RydawgRydawg USBeta

    Hey Jon, I was able to reproduce this in the attached sample project. This issue happens if the device admin is active when you change the xml file and redeploy. In the attached project do the following to reproduce:

    1. Start debugging the app. You should see a form with a button that says Test1.
    2. Click the Test1 button and you should get a prompt to activate the device admin. Click Activate.
    3. Stop debugging.
    4. Opens strings.xml and change Test1 to something else.
    5. Start debugging again. You should see that the text on the button stays at Test1. If I first remove the device admin before changing the string then I don't have any issues (code to remove is commented out in Activity1.cs).
Sign In or Register to comment.