Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot resolve symble 'R' #284

Closed
bjzhou opened this issue Nov 10, 2016 · 33 comments
Closed

Cannot resolve symble 'R' #284

bjzhou opened this issue Nov 10, 2016 · 33 comments

Comments

@bjzhou
Copy link

bjzhou commented Nov 10, 2016

使用freeline后有概率导致Android Studio无法识别R.java,必须重新sync gradle一下

@lomanyong
Copy link
Member

@bjzhou 能够给个复现路径,以及是哪个module的R.java无法识别吗?比如是app module还是library module这样的信息。

@bjzhou
Copy link
Author

bjzhou commented Nov 11, 2016

@lomanyong 找到复现路径了,实际包名和build.gradle里applicationId指定的包名不一致时就会出现这个bug,就是app module

@lomanyong
Copy link
Member

@bjzhou 是在manifest中定义了不一样的包名?还是使用applicationIdSuffix之类的属性呢?

@bjzhou
Copy link
Author

bjzhou commented Nov 11, 2016

@lomanyong 改的是app的build.gradle里defaultConfig.applicationId这一项,也就是manifest定义了不一样的包名

@lomanyong
Copy link
Member

@bjzhou 试了一下,这个case确实比较特殊...还会引发一些其他奇怪的问题...后面单独发个小版本给你测试看看...

@Rainbow-556
Copy link

你好,我的项目也是这种情况,在app的build.gradle定义了两个applicationId,其中debug包和正式包的applicationId不一样,所以每次使用freeline构建的时候都识别不了R文件,求解决方法。

@lomanyong
Copy link
Member

lomanyong commented Nov 25, 2016

@Rainbow-556 贴出个大概的配置看下?

解决方法就是等待发版吧(预计1-2个小版本内会解决这个问题)...因为这个改动比较特殊...所以还得多测试一下...

@Rainbow-556
Copy link

Rainbow-556 commented Nov 25, 2016

默认自己构建的是innerDebug包,下面是build.gradle的相关部分:

productFlavors{
        official{
            applicationId "com.xxx.app"
            manifestPlaceholders = [PACKAGE:applicationId,APPNAME:"xxx"]
        }
        inner{
            applicationId "com.xxxtest.app"
            manifestPlaceholders = [PACKAGE:applicationId,APPNAME:"xxxtest"]
        }
}

@wankey
Copy link

wankey commented Nov 28, 2016

0.8.2版本有同样的现象发生。

Manifest中的packageName和applicationId不一致时,干净的项目用freeline第一次编译成功,修改一行代码后再执行freeline,会报出Manifest中的packageName目录下的R.java找不到(IOError: [Errno 2] No such file or directory),同时,AS编辑器中也会找不到R.java。

@lomanyong
Copy link
Member

@wankey python会报找不到?如果是的话,麻烦贴出日志来看下...

Manifest中的packageName和applicationId不一致是个特殊的case,请耐心等下发版解决吧...

@wankey
Copy link

wankey commented Nov 28, 2016

~‹› $ python freeline.py
[INFO] preparing for tasks...
[-][connect_device_task] finished. in 0.2s
[-][gradle_aapt_task] failed. in 0.4s
[-][framework] failed. in 0s
[-][app] failed. in 0s
[-][merge_dex_task] failed. in 0s
[-][gradle_sync_task] failed. in 0s
[-][clean_cache_task] failed. in 0s
[-][update_stat_task] failed. in 0s
[ERROR] --------------------------------------------------------
[ERROR] Freeline ERROR
[ERROR] --------------------------------------------------------
Traceback (most recent call last):
File "${projectFolder}/freeline/freeline_core/task.py", line 123, in execute
self.task.execute()
File "${projectFolder}/freeline/freeline_core/gradle_inc_build.py", line 170, in execute
self._invoker.check_other_modules_resources()
File "${projectFolder}/freeline/freeline_core/gradle_inc_build.py", line 447, in check_other_modules_resources
self.__modify_main_r()
File "${projectFolder}/freeline/freeline_core/gradle_inc_build.py", line 460, in __modify_main_r
write_file_content(main_r_fpath, buf)
File "${projectFolder}/freeline/freeline_core/utils.py", line 118, in write_file_content
with open(target_path, 'w') as fp:
IOError: [Errno 2] No such file or directory: u'${projectFolder}/app/build/freeline/app/backup/${packageName}/R.java'

[ERROR] --------------------------------------------------------
[ERROR] unexpected exception within task
[ERROR] --------------------------------------------------------
[DEBUG] Prepare tasks time: 0.2s
[DEBUG] Task engine running time: 0.4s
[DEBUG] Total time: 0.6s
[DEBUG] --------------------------------------------------------

@wankey
Copy link

wankey commented Nov 28, 2016

第二次编译时有修改过布局文件等涉及到R文件变更的代码。
如果只是纯代码修改python不会报找不到R文件

@lomanyong
Copy link
Member

@wankey 感谢提供日志...这个问题的修复这周会发版解决.

@wankey
Copy link

wankey commented Nov 28, 2016

@lomanyong, 不客气,很期待能解决这个问题。使用freeline在开发过程中节约了我们许多时间。感谢你们!

@Rainbow-556
Copy link

确实freeline帮我们节省了很多时间,感谢freeline团队,哈哈

@lomanyong
Copy link
Member

@bjzhou @Rainbow-556 @wankey hi,这样修改一下你的项目配置,修改版本号为:0.8.2.1611302135

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        ......
        classpath 'com.antfortune.freeline:gradle:0.8.2.1611302135'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

然后执行一下这个命令:

win: gradlew initFreeline -PfreelineVersion=0.8.2.1611302135
linux/mac: ./gradlew initFreeline -PfreelineVersion=0.8.2.1611302135

执行 python freeline.py -v 确认一下 freeline 的版本为:0.8.2.1611302135

最后,重新使用freeline编译看下是否解决了你的问题。

@wankey
Copy link

wankey commented Dec 1, 2016

@lomanyong,
试过修改代码、布局、资源文件,没有再出现Cannot resolve symble 'R'的现象

@lomanyong
Copy link
Member

@wankey ok~0.8.3 版本发布后彻底解决这个问题..

@Rainbow-556
Copy link

刚刚使用0.8.2.1611302135这个版本测试了,没有出现Cannot resolve symble 'R'的问题,但是会导致我的AS布局不能预览,要clean project之后才可以预览,但是在全构建时,又不能预览了。我换回0.8.2这个版本,就一直能预览。不知道是什么问题....

@lomanyong
Copy link
Member

@Rainbow-556 不能预览提示什么呢?

@Rainbow-556
Copy link

就是在xml布局编辑器的右边都没有出现preview窗口,点击左下角的design也不能预览,并且没有提示信息,预览手机窗口是全黑的,试过更换预览的api版本也没用。

@lomanyong
Copy link
Member

@Rainbow-556 看了一下貌似没有太多关于这个地方的修改,以前有解决过这个问题。一直出现这个问题吗?

@wankey 你是否有遇见过类似的情况呢?

@wankey
Copy link

wankey commented Dec 1, 2016

@lomanyong
0.8.2.1611302135中没有出现这个现象

附上AS信息
Android Studio 2.2.2
Build #AI-145.3360264, built on October 18, 2016
JRE: 1.8.0_112-release-b05 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

@Rainbow-556
Copy link

@lomanyong 我AS版本是2.2.1,使用0.8.2.1611302135版本一直有这种情况,我试过重启AS也没用,看今天我有时间的话我再试试,再来反馈。目前我暂时切换回0.8.2这个版本了。

@Rainbow-556
Copy link

@lomanyong 我刚刚把AS升级到2.2.2,然后使用0.8.2.1611302135版本,一切正常,一直能预览,可能是AS版本的原因吧。非常感谢你们修复了不同包名的这个问题

@shingohu
Copy link

shingohu commented Dec 21, 2016

@lomanyong 表示还存在这个问题
版本0.8.4
AS配置

 freeline {
        hack true
        productFlavor 'tt'
        buildScript './gradlew assembleTtDebug'
       // applicationProxy false
    }


 tt {
            applicationIdSuffix ".test"
          
         
            resValue("string", "app_name", "测试环境")
        }


代码飘红,找不到R 可以运行

@shingohu
Copy link

另外#283 启动时卡住 好像也是因为这个 去掉 applicationIdSuffix ".test" 一切就正常了

@lomanyong
Copy link
Member

@shingohu 启动卡主应该跟这个没啥关系...

具体找不到 R.java 的那个过程可以说一下吗?怎么操作的?

@shingohu
Copy link

@lomanyong
1.我的程序打.test的包就会卡在启动界面,打生产的包就没有问题
2.具体过程不好重现,大概就是运行.test包后,在修改某个Activity,在运行就找不到R.java了,也是生产的包没问题

@lomanyong
Copy link
Member

@shingohu freeline 只在 debug 包起作用,生产的包一般不行的...

@hhllf61
Copy link

hhllf61 commented Nov 23, 2017

Traceback (most recent call last):
File "/Users/liuf/AndroidStudioProjects/Angler3.0/freeline/freeline_core/task.py", line 123, in execute
self.task.execute()
File "/Users/liuf/AndroidStudioProjects/Angler3.0/freeline/freeline_core/gradle_tools.py", line 233, in execute
self._fill_cache_map(all_modules)
File "/Users/liuf/AndroidStudioProjects/Angler3.0/freeline/freeline_core/gradle_tools.py", line 240, in _fill_cache_map
self._save_module_stat(module['name'], module['path'])
File "/Users/liuf/AndroidStudioProjects/Angler3.0/freeline/freeline_core/gradle_tools.py", line 300, in _save_module_stat
self.__save_stat(module_name, os.path.join(sub_dir_path, fn))
File "/Users/liuf/AndroidStudioProjects/Angler3.0/freeline/freeline_core/gradle_tools.py", line 316, in __save_stat
self._stat_cache[module][fpath] = {'mtime': os.path.getmtime(fpath), 'md5': get_md5(fpath)}
File "/Users/liuf/AndroidStudioProjects/Angler3.0/freeline/freeline_core/utils.py", line 84, in get_md5
target_file = open(fpath, 'rb')
IOError: [Errno 21] Is a directory: u'/Users/liuf/AndroidStudioProjects/Angler3.0/app/src/main/res/layout_club/layout'

升级Android studio3.0,gradle 后报这个

@hhllf61
Copy link

hhllf61 commented Nov 23, 2017

gradle是 4.3 版本,以前freeline是0.8.7没问题现在都升级为0.8.8出现

@ding33211
Copy link

同上

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants