【EasyGBD】プロジェクトコンパイルの流れ

目次

1 Google Play では、アプリが API レベル 30 以上をターゲットにする必要があります

編集

2 AndroidX への移行

3 ビルド構成

コンパイルと実行に成功しました

残された問題


1 Google Play では、アプリが API レベル 30 以上をターゲットにする必要があります

Google Play requires that apps target API level 30 or higher. but if I make that , the project can't be normal
If your project is encountering issues after targeting API level 30 or higher, it is likely due to changes and restrictions introduced in the newer Android versions. Here are some common reasons why your project may not be functioning normally after targeting API level 30:

1. **Permissions Changes**: Android 11 (API level 30) introduced more restrictions on accessing certain sensitive permissions, such as location, storage, etc. If your app was previously using these permissions without proper justification or handling, it might be causing issues.

2. **Background Execution Limits**: Android 10 (API level 29) and higher have stricter background execution limits, which means background services and tasks are limited in their execution time. If your app relies heavily on background processes, it might be affected by these limitations.

3. **Scoped Storage**: Android 10 introduced scoped storage, and this behavior is further refined in Android 11. If your app was using external storage in a non-compliant way, it could lead to issues when targeting API level 30.

4. **Network Security Configuration**: Starting from Android 9 (API level 28), there are stricter requirements for network security. If your app is communicating with servers using HTTP instead of HTTPS, it might cause issues.

To resolve these issues and make your project work normally while targeting API level 30 or higher, you need to update your codebase and make it compatible with the new changes and restrictions. Here are some steps to help you proceed:

1. **Review Permissions**: Make sure your app requests permissions properly, and handle the cases when users deny or revoke them. Be sure to follow the best practices for handling location, storage, and other sensitive permissions.

2. **Adapt to Background Execution Limits**: If your app relies on background tasks or services, ensure they comply with the new background execution restrictions. Use foreground services where appropriate and optimize background tasks.

3. **Scoped Storage**: Update your app to use scoped storage instead of accessing external storage directly. This means using the Storage Access Framework (SAF) or File APIs provided by Android.

4. **Network Security**: Ensure your app communicates with servers using secure HTTPS connections. Update your network security configuration to comply with the new requirements.

5. **Test and Debug**: After making the necessary changes, thoroughly test your app on devices running API level 30 or higher. This will help you identify any remaining issues and ensure your app functions normally.

It's important to keep your app up-to-date with the latest Android changes to maintain compatibility and security. Targeting the latest API levels is essential for getting your app approved on Google Play and providing a better user experience for your users on modern Android devices.

2 AndroidX への移行

 AndroidX への移行

Version 28 (intended for Android Pie and below) is the last version of the legacy support library, so we recommend that you migrate to AndroidX libraries when using Android Q and moving forward. The IDE can help with this: Refactor > Migrate to AndroidX...

The message you provided is a recommendation from Google when you are using older versions of the Android Support Library (version 28 or below) in your Android project and targeting Android Q (Android 10) or higher. Starting from Android Q, Google introduced AndroidX, which is a major improvement and replacement for the previous Android Support Library.

AndroidX is a set of libraries that offer better features, performance, and maintainability compared to the old support library. It provides backward compatibility with older Android versions and is the recommended approach for handling app development, especially when targeting Android Q and newer versions.

To migrate your project to AndroidX, you can use the "Migrate to AndroidX" tool provided by Android Studio. Here's how to do it:

1. Open your Android project in Android Studio.

2. Go to the "Refactor" menu.

3. Select "Migrate to AndroidX..." from the dropdown.

4. A dialog box will appear, showing a preview of the changes that will be made during the migration process. Review the changes and make sure you have a backup of your project before proceeding.

5. Click "Do Refactor" to start the migration process.

Android Studio will automatically update your project's dependencies and refactor your code to use AndroidX libraries. After the migration, you should review your project to ensure everything works correctly and resolve any issues that might have arisen during the migration.

By migrating to AndroidX, you ensure that your app is using the latest and recommended Android development libraries and that it remains compatible with the latest Android versions and features. It's a best practice to keep your app updated and aligned with the latest Android development standards.

3 ビルド構成

import androidx.lifecycle.BuildConfig;

It seems you are trying to import the `BuildConfig` class from the `androidx.lifecycle` package. However, importing `BuildConfig` from the `androidx.lifecycle` package is not correct, as `BuildConfig` is usually auto-generated for each individual Android module and not part of any specific AndroidX package.

Instead, you should import the `BuildConfig` class from your own app's package. The `BuildConfig` class is automatically generated by the Android build system for each Android module (e.g., app module) in your project. It contains constants and flags related to your app's build configuration.

To use the `BuildConfig` class, follow these steps:

1. Ensure you have the `BuildConfig.java` file in your app module. It is usually located in the `app/build/generated/source/buildConfig` directory.

2. Import the `BuildConfig` class from your app's package in your Java/Kotlin code. The import statement should look like this (replace `com.your.package` with your actual app's package name):

   ```java
   import com.your.package.BuildConfig;
   ```

3. You can now access the constants and flags defined in the `BuildConfig` class in your code. For example, if you have a constant named `DEBUG` defined in `BuildConfig`, you can use it like this:

   ```java
   if (BuildConfig.DEBUG) {
       // Code to run in debug mode
   } else {
       // Code to run in release mode
   }
   ```

Remember to replace `com.your.package` with your actual app's package name in the import statement. If you're not sure about your app's package name, you can find it in the `AndroidManifest.xml` file or in your app's `build.gradle` file under the `applicationId` field.

Keep in mind that the `BuildConfig` class is specific to each module, so if you have multiple modules in your project (e.g., different flavors or build types), each module will have its own `BuildConfig` class.

コンパイルと実行に成功しました

残された問題

  2.8 への接続に失敗する

 

おすすめ

転載: blog.csdn.net/dualvencsdn/article/details/132062015