在Android Studio中更改xml布局文件后需要重建 [英] Rebuild required after changing xml layout files in Android Studio

查看:537
本文介绍了在Android Studio中更改xml布局文件后需要重建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发android应用程序,并且正在使用Android Studio.

I am developing android applications and I am using Android Studio.

但是有一个问题.当我更改 source 并运行应用程序时,它运行正常,但是当我更改资源时,它直到我执行 Clean Project 时才更改>.例如我添加一个按钮并运行该应用程序,该按钮不存在,但是当我执行一个干净的项目时,该按钮就在那里.访问新添加的视图的id时,Android Studio显示错误.

There is a problem though. When I change the source and I run the app it works fine, But when I change a resource it does not change until I do a Clean Project. e.g. I add a button and run the app, the button does not exist but when I do a clean project it is there. Android studio shows an error when accessing the id of the newly added view.

请帮助我解决此问题.任何帮助将不胜感激.

Please help me solve this problem. Any help would be much appreciated.

其他信息: -Android Studio版本:1.3.1 -操作系统:Windows -Gradle版本:2.6

Additional information: -Android Studio version: 1.3.1 -Operating system: windows -Gradle version: 2.6

我正在使用gradle这样将多个目录作为我的资源:

I am having multiple directories as my resources with gradle like this:

sourceSets{
     main  {
         manifest.srcFile 'src/main/AndroidManifest.xml'
         java.srcDirs = ['src/main/java', '.apt_generated']
         aidl.srcDirs = ['src/main/aidl', '.apt_generated']
         res.srcDirs = [
            'src/main/res',
            'src/main/res/layouts/test',
            'src/main/res/layouts/login',
            'src/main/res/layouts/main',
            'src/main/res/layouts/includes'
        ]
    }
}

当我尝试以更改的布局运行项目时,它说:

When i try to run the project with changed layout it says:

No apk changes detected. Skipping file upload, force stopping package instead. DEVICE SHELL COMMAND: am force-stop com.my.package

No apk changes detected. Skipping file upload, force stopping package instead. DEVICE SHELL COMMAND: am force-stop com.my.package

推荐答案

我通过不使用嵌套的资源文件夹解决了我的问题.我有多个资源文件夹.解决方法是在res文件夹旁边而不在其中创建其他资源文件夹.我的gradle像这样改变:

I resolved my problem by not using nested resource folders. I have multiple resource folders though. The workaround is creating your additional resource folders beside your res folder not inside it. My gradle changes like this:

sourceSets{
     main  {
         manifest.srcFile 'src/main/AndroidManifest.xml'
         java.srcDirs = ['src/main/java', '.apt_generated']
         aidl.srcDirs = ['src/main/aidl', '.apt_generated']
         res.srcDirs = [
            'src/main/res',
            'src/main/test',
            'src/main/login',
            'src/main/main',
            'src/main/includes'
        ]
    }
}

其他资源文件夹中的所有更改现在都可以生效,而无需清理和重建项目.希望对您有帮助.

All the changes in additional resource folders now take effect without cleaning and rebuilding the project. I hope it helps you.

这篇关于在Android Studio中更改xml布局文件后需要重建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆