无法创建示例数据目录 - Android Studio
Can't create Sample Data Directory - Android Studio
我正在尝试使用 Android Studio 创建示例数据目录,方法是单击项目视图中的应用程序,然后右键单击以找到菜单项新建 > 示例数据目录。
它不起作用。
通过 android 工作室创建目录并不总是有效。您可能需要在目录结构中手动创建目录(位于 /app/sampledata/),而不使用 Android Studio。创建后(例如,通过 Windows Explorer),它应该会显示在 Android Studio 中。有关一般样本数据的更多信息,请参阅以下答案:
"Unlike resources like images, fonts, etc. The sample data does not go in /res/ (they are not compiled with the app, hence. It is probably easier to filter them out by putting them in a totally separate directory). They go in /app/sampledata/, for example: /app/sampledata/image.png."
除非您的问题恰好不同,否则这是一个只影响 Windows 的已知问题。正如我所发现的,它与文件路径中的 'C:\' 有关。
https://issuetracker.google.com/issues/124553391
如 Shawn 所述,您需要手动创建目录。
我一直无法让图像在预览器中实际显示,我怀疑这也可能是由文件路径错误引起的。
您可以按照以下步骤在 Android Studio 中创建示例数据目录:
将目录结构视图由Android改为Project如下
右击应用程序文件夹和select新建->目录
最后,给你的目录起个名字,在你的例子中,它应该是sampledata
我已经创建了 sampledata 目录,这就是它显示 "Directory already exists".
的原因
就是这样。你已经做到了。请记住,Android Studio 还支持从 json 文件加载样本数据。您只需提供驻留在 json 文件中的密钥的完全限定名称。
Ex- 如果您的 json 文件在 Json 数组 student 中包含键 name,那么您必须将其指定为“@sample/your_student_file.json/student/name”才能使用键 name.
中存在的值
在文件资源管理器的 app 文件夹内,您可以创建一个新文件夹(示例数据),该文件夹将反映在您的 android 工作室中。
我正在尝试使用 Android Studio 创建示例数据目录,方法是单击项目视图中的应用程序,然后右键单击以找到菜单项新建 > 示例数据目录。
它不起作用。
通过 android 工作室创建目录并不总是有效。您可能需要在目录结构中手动创建目录(位于 /app/sampledata/),而不使用 Android Studio。创建后(例如,通过 Windows Explorer),它应该会显示在 Android Studio 中。有关一般样本数据的更多信息,请参阅以下答案:
"Unlike resources like images, fonts, etc. The sample data does not go in /res/ (they are not compiled with the app, hence. It is probably easier to filter them out by putting them in a totally separate directory). They go in /app/sampledata/, for example: /app/sampledata/image.png."
除非您的问题恰好不同,否则这是一个只影响 Windows 的已知问题。正如我所发现的,它与文件路径中的 'C:\' 有关。
https://issuetracker.google.com/issues/124553391
如 Shawn 所述,您需要手动创建目录。
我一直无法让图像在预览器中实际显示,我怀疑这也可能是由文件路径错误引起的。
您可以按照以下步骤在 Android Studio 中创建示例数据目录:
将目录结构视图由Android改为Project如下
右击应用程序文件夹和select新建->目录
最后,给你的目录起个名字,在你的例子中,它应该是sampledata
我已经创建了 sampledata 目录,这就是它显示 "Directory already exists".
的原因就是这样。你已经做到了。请记住,Android Studio 还支持从 json 文件加载样本数据。您只需提供驻留在 json 文件中的密钥的完全限定名称。
Ex- 如果您的 json 文件在 Json 数组 student 中包含键 name,那么您必须将其指定为“@sample/your_student_file.json/student/name”才能使用键 name.
中存在的值在文件资源管理器的 app 文件夹内,您可以创建一个新文件夹(示例数据),该文件夹将反映在您的 android 工作室中。