Trong Android Studio, hãy mở dự án mẫu Hello Sceneform (Biểu mẫu Xin chào) nằm trong thư mục con của app (ứng dụng) trong thư mục sceneform-android-sdk.
Chuẩn bị thiết bị hoặc trình mô phỏng
Bạn có thể chạy các ứng dụng thực tế tăng cường trên một thiết bị được hỗ trợ hoặc trong Trình mô phỏng Android:
Có một số yêu cầu bổ sung để chạy
các ứng dụng theo dõi trong trình mô phỏng:
Bạn cần có Trình mô phỏng Android phiên bản 27.2.9 trở lên.
OpenGL ES 3.0 trở lên phải được hỗ trợ và bật trong Trình mô phỏng
Android.
Đảm bảo trình mô phỏng của bạn được định cấu hình để dùng phiên bản mới nhất. Trong
bảng Điều khiển mở rộng
(
trên Thanh công cụ), hãy chọn Settings > Advanced > OpenGL ES API level >
Trình kết xuất tối đa (lên đến OpenGL ES 3.1), rồi khởi động lại trình mô phỏng.
Chạy trình mô phỏng, tương tác nhanh với trình mô phỏng, sau đó kiểm tra xem bạn có đang sử dụng OpenGL ES 3.0 trở lên hay không:
adb logcat | grep eglMakeCurrent
Nếu thấy ver 3 0 trở lên, bạn có thể chạy các ứng dụng Sceneform.
Nếu bạn thấy phiên bản thấp hơn, thì GPU máy tính để bàn của bạn không hỗ trợ OpenGL ES 3.0 và bạn phải dùng một thiết bị được hỗ trợ để chạy các ứng dụng Sceneform.
Chạy mẫu
Đảm bảo thiết bị Android của bạn đã kết nối với máy phát triển và nhấp vào Run (Chạy) trong Android Studio. Sau đó, hãy chọn thiết bị của bạn làm mục tiêu triển khai rồi nhấp vào OK.
Android Studio tạo dự án của bạn thành một tệp APK có thể gỡ lỗi, cài đặt tệp APK, sau đó chạy ứng dụng trên thiết bị. Để biết thêm thông tin, hãy xem phần Tạo và chạy ứng dụng của bạn.
Bạn có thể được nhắc cài đặt hoặc cập nhật Google Play Services for AR (nếu bị thiếu hoặc lỗi thời). Chọn TIẾP TỤC để cài đặt từ Cửa hàng Google Play.
Ứng dụng Hello Sceneform (Biểu mẫu Xin chào) cho phép bạn đặt và thao tác các mô hình Android nhỏ trên các bề mặt phẳng.
[null,null,["Cập nhật lần gần đây nhất: 2022-09-26 UTC."],[[["\u003cp\u003eInstall Android Studio 3.1+ and Android SDK Platform 7.0+ to set up your development environment, along with basic Android development knowledge.\u003c/p\u003e\n"],["\u003cp\u003eDownload or clone the Sceneform Samples project and open the Hello Sceneform sample in Android Studio.\u003c/p\u003e\n"],["\u003cp\u003ePrepare a supported device or emulator with Google Play Services for AR and ensure it meets the specified requirements for running Sceneform apps.\u003c/p\u003e\n"],["\u003cp\u003eBuild and run the sample app on your device or emulator, potentially installing or updating Google Play Services for AR if needed.\u003c/p\u003e\n"],["\u003cp\u003eTo integrate Sceneform into existing projects, enable ARCore, add the Sceneform library to your app's \u003ccode\u003ebuild.gradle\u003c/code\u003e file, and configure compile options if necessary.\u003c/p\u003e\n"]]],["To get started, install Android Studio (version 3.1+) with Android SDK Platform 7.0+. Download or clone the Sceneform Samples, then open the \"Hello Sceneform\" project in Android Studio. Ensure your device or emulator supports OpenGL ES 3.0 or higher. Run the sample by connecting your device and pressing \"Run.\" To use Sceneform in an existing project, enable ARCore and add the Sceneform library to your app's `build.gradle` file.\n"],null,["# Sceneform Quickstart for Android\n\nSet up your development environment\n-----------------------------------\n\n- Install [Android Studio](https://developer.android.com/studio/index.html)\n version 3.1 or higher with Android SDK Platform version 7.0 (API level 24)\n or higher.\n\n- You will need a basic understanding of Android development. If you are new\n to Android, see\n [Building your first Android app for beginners](//developer.android.com/training/basics/firstapp/index.html).\n\nOpen the sample project\n-----------------------\n\nGet the sample projects. You can either:\n\n- Download and extract the [Sceneform Samples](//github.com/google-ar/sceneform-android-sdk/releases)\n\n -or-\n- Clone the repository with the following command:\n\n \u003cbr /\u003e\n\n ```\n git clone https://github.com/google-ar/sceneform-android-sdk.git\n ```\n\n \u003cbr /\u003e\n\nIn Android Studio, open the **Hello Sceneform** sample project, located in the **app** subdirectory within the `sceneform-android-sdk` directory.\n\nPrepare your device or emulator\n-------------------------------\n\nYou can run AR apps on a [supported device](/ar/discover/supported-devices) or\nin the Android Emulator:\n\n- In the emulator, you must sign into the Google Play Store or [update Google Play Services for AR](/sceneform/develop/emulator#update-arcore) manually.\n\nThere are additional requirements to run\nSceneform apps in the emulator:\n\n- You need **Android Emulator** version **27.2.9** or later.\n- **OpenGL ES 3.0** or higher must be supported and enabled in the Android\n Emulator.\n\n - Make sure your emulator is configured to use the latest version. In the\n Extended controls panel\n (\n on the Toolbar), select **Settings \\\u003e Advanced \\\u003e OpenGL ES API level \\\u003e\n Renderer maximum (up to OpenGL ES 3.1)**, and then restart the emulator.\n\n - Run the emulator, briefly interact with the emulated deivce, then check\n whether OpenGL ES 3.0 or higher is being used:\n\n adb logcat | grep eglMakeCurrent\n\n If you see `ver 3 0` or higher version, then you can run Sceneform apps.\n If you see a lower version, then your desktop GPU does not support\n OpenGL ES 3.0 and you must use a\n [supported device](/ar/discover/supported-devices) to run Sceneform\n apps.\n\nRun the sample\n--------------\n\nMake sure your Android device is connected to the development machine and click\n**Run** in Android Studio. Then, choose your device\nas the deployment target and click **OK**.\n\nAndroid Studio builds your project into a debuggable APK, installs the APK, and\nthen runs the app on your device. For more information, see [Build and Run Your App](//developer.android.com/studio/run/index.html).\n\nYou may be prompted to install or update [Google Play Services for AR](//play.google.com/store/apps/details?id=com.google.ar.core)\nif it is missing or out of date. Select **CONTINUE** to install it from\nGoogle Play Store.\n\nThe **Hello Sceneform** app lets you place and manipulate Android figurines on\nflat surfaces.\nYour browser does not support the video tag.\n\nAdd Sceneform to an existing project\n------------------------------------\n\nTo use Sceneform in an existing project:\n\n1. Follow the steps to [Enable ARCore](/ar/develop/java/enable-arcore) in your app\n\n2. Add the Sceneform library to your **app's** `build.gradle` file:\n\n android {\n // Sceneform libraries use language constructs from Java 8.\n // Add these compile options if targeting minSdkVersion \u003c 26.\n compileOptions {\n sourceCompatibility 1.8\n targetCompatibility 1.8\n }\n }\n\n dependencies {\n ...\n\n // Provides ArFragment, and other UX resources.\n implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.15.0'\n\n // Alternatively, use ArSceneView without the UX dependency.\n implementation 'com.google.ar.sceneform:core:1.15.0'\n }\n\nNext steps\n----------\n\n- Try building and running [other sample projects](/sceneform/develop/samples) in the ARCore SDK and Sceneform samples.\n- Learn how to [Enable ARCore](/ar/develop/java/enable-arcore) in your app.\n- Review [Runtime Considerations](/ar/develop/developer-guides/runtime-considerations).\n- Review [Design Guidelines](/ar/develop/developer-guides/design-guidelines)."]]