Lỗi phân tích cú pháp trên android 4.0.4 năm 2024

Bản cập nhật nhỏ này hỗ trợ khả năng tương thích với các tính năng và chế độ cài đặt mặc định mới cho chế độ hiển thị gói trong Android 11.

Trong các phiên bản Android trước, bạn có thể xem danh sách tất cả ứng dụng được cài đặt trên một thiết bị. Kể từ Android 11 (API cấp 30), theo mặc định, các ứng dụng chỉ có quyền truy cập vào một danh sách gói được cài đặt đã lọc. Để xem danh sách nhiều ứng dụng hơn trên hệ thống, giờ đây, bạn cần trong tệp kê khai Android của thư viện hoặc ứng dụng.

Trình bổ trợ Android cho Gradle 4.1 trở lên đã tương thích với bản khai báo

`android { defaultConfig {

// Required when setting minSdkVersion to 20 or lower
multiDexEnabled = true
}

compileOptions {

// Flag to enable support for the new language APIs
isCoreLibraryDesugaringEnabled = true
// Sets Java compatibility to Java 8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
} }

`

dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.0.4") }

7 mới. Tuy nhiên, các phiên bản cũ hơn không tương thích. Nếu bạn thêm phần tử

`android { defaultConfig {

// Required when setting minSdkVersion to 20 or lower
multiDexEnabled = true
}

compileOptions {

// Flag to enable support for the new language APIs
isCoreLibraryDesugaringEnabled = true
// Sets Java compatibility to Java 8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
} }

`

dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.0.4") }

7 hoặc nếu bạn bắt đầu dựa vào thư viện hoặc SDK hỗ trợ cho Android 11 nhắm mục tiêu, bạn có thể gặp lỗi hợp nhất tệp kê khai khi tạo ứng dụng.

Để giải quyết vấn đề này, chúng tôi sẽ phát hành một bộ bản vá cho AGP 3.3 trở lên. Nếu bạn đang sử dụng phiên bản AGP cũ, hãy lên một trong các phiên bản sau:

Nếu bạn đang dùng phiên bản AGP... ...hãy nâng cấp lên: 4.0.* 4.0.1 3.6.* 3.6.4 3.5.* 3.5.4 3.4.* 3.4.3 3.3.* 3.3.3

Để biết thêm thông tin về tính năng mới này, hãy xem nội dung Chế độ hiển thị gói trong Android 11.

Tính năng mới

Phiên bản trình bổ trợ Android cho Gradle này có các tính năng mới sau đây.

Hỗ trợ Trình phân tích bản dựng Android Studio

Cửa sổ Trình phân tích bản dựng giúp bạn tìm hiểu và chẩn đoán các vấn đề xảy ra với quá trình tạo bản dựng, chẳng hạn như tính năng tối ưu hoá bị vô hiệu hoá và các tác vụ được định cấu hình không đúng cách. Tính năng này chỉ có sẵn khi bạn sử dụng Android Studio 4.0 trở lên với trình bổ trợ Android cho Gradle

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

0 trở lên. Bạn có thể mở cửa sổ Trình phân tích bản dựng trong Android Studio như sau:

  1. Nếu chưa thực hiện việc này, bạn hãy tạo một ứng dụng bằng cách chọn Build (Bản dựng) > Make Project (Tạo dự án) trên thanh trình đơn.
  2. Hãy chọn View > Tool Windows > Build (Xem > Cửa sổ công cụ > Bản dựng) trên thanh trình đơn.
  3. Trong cửa sổ Build (Bản dựng), hãy mở cửa sổ Trình phân tích bản dựng theo một trong các cách sau:
    • Sau khi Android Studio hoàn tất quá trình tạo dự án, hãy nhấp vào thẻ Build Analyzer (Trình phân tích bản dựng).
    • Sau khi Android Studio hoàn tất quá trình tạo dự án, hãy nhấp vào đường liên kết ở bên phải cửa sổ Build Output (Đầu ra bản dựng).

Lỗi phân tích cú pháp trên android 4.0.4 năm 2024

Cửa sổ Build Analyzer (Trình phân tích bản dựng) sắp xếp các vấn đề về bản dựng có thể xảy ra trong một cây ở bên trái. Bạn có thể kiểm tra và nhấp vào từng vấn đề để tìm hiểu thông tin chi tiết về vấn đề đó trong bảng điều khiển bên phải. Khi phân tích bản dựng, Android Studio sẽ tính toán tập hợp tác vụ xác định thời lượng của bản dựng và cung cấp hình ảnh để giúp bạn hiểu tác động của từng tác vụ này. Bạn cũng có thể xem thông tin chi tiết về các cảnh báo bằng cách mở rộng nút Warnings (Cảnh báo).

Để tìm hiểu thêm, hãy đọc bài viết xác định tốc độ hồi quy của bản dựng.

Đơn giản hoá thư viện Java 8 trong D8 và R8

Trình bổ trợ Android cho Gradle hiện đã hỗ trợ việc sử dụng một số API ngôn ngữ Java 8 mà không yêu cầu cấp độ API tối thiểu cho ứng dụng.

Thông qua một quy trình có tên là đơn giản hoá (desugaring), trình biên dịch DEX D8 trong Android Studio 3.0 trở lên đã hỗ trợ đáng kể các tính năng ngôn ngữ Java 8 (chẳng hạn như biểu thức lambda, phương thức giao diện mặc định, thử với các tài nguyên và các tính năng khác). Trong Android Studio 4.0, công cụ đơn giản hoá đã được mở rộng để có thể đơn giản hoá các API ngôn ngữ Java. Điều này có nghĩa là bạn hiện có thể đưa các API ngôn ngữ tiêu chuẩn chỉ có trong các bản phát hành Android gần đây (chẳng hạn như

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

  1. vào các ứng dụng hỗ trợ các phiên bản Android cũ.

Bộ API sau đây được hỗ trợ trong bản phát hành này:

  • Luồng tuần tự (

    android { // The default value for each feature is shown below. You can change the value to // override the default behavior. buildFeatures {

    // Determines whether to generate a BuildConfig class.  
    buildConfig = true  
    // Determines whether to support View Binding.  
    // Note that the viewBinding.enabled property is now deprecated.  
    viewBinding = false  
    // Determines whether to support Data Binding.  
    // Note that the dataBinding.enabled property is now deprecated.  
    dataBinding = false  
    // Determines whether to generate binder classes for your AIDL files.  
    aidl = true  
    // Determines whether to support RenderScript.  
    renderScript = true  
    // Determines whether to support injecting custom variables into the module’s R class.  
    resValues = true  
    // Determines whether to support shader AOT compilation.  
    shaders = true  
    
    } }

    2)
  • Một tập hợp con của

    android { // The default value for each feature is shown below. You can change the value to // override the default behavior. buildFeatures {

    // Determines whether to generate a BuildConfig class.  
    buildConfig = true  
    // Determines whether to support View Binding.  
    // Note that the viewBinding.enabled property is now deprecated.  
    viewBinding = false  
    // Determines whether to support Data Binding.  
    // Note that the dataBinding.enabled property is now deprecated.  
    dataBinding = false  
    // Determines whether to generate binder classes for your AIDL files.  
    aidl = true  
    // Determines whether to support RenderScript.  
    renderScript = true  
    // Determines whether to support injecting custom variables into the module’s R class.  
    resValues = true  
    // Determines whether to support shader AOT compilation.  
    shaders = true  
    
    } }

    3
  • android { // The default value for each feature is shown below. You can change the value to // override the default behavior. buildFeatures {

    // Determines whether to generate a BuildConfig class.  
    buildConfig = true  
    // Determines whether to support View Binding.  
    // Note that the viewBinding.enabled property is now deprecated.  
    viewBinding = false  
    // Determines whether to support Data Binding.  
    // Note that the dataBinding.enabled property is now deprecated.  
    dataBinding = false  
    // Determines whether to generate binder classes for your AIDL files.  
    aidl = true  
    // Determines whether to support RenderScript.  
    renderScript = true  
    // Determines whether to support injecting custom variables into the module’s R class.  
    resValues = true  
    // Determines whether to support shader AOT compilation.  
    shaders = true  
    
    } }

    4
  • Các mục bổ sung gần đây cho

    android { // The default value for each feature is shown below. You can change the value to // override the default behavior. buildFeatures {

    // Determines whether to generate a BuildConfig class.  
    buildConfig = true  
    // Determines whether to support View Binding.  
    // Note that the viewBinding.enabled property is now deprecated.  
    viewBinding = false  
    // Determines whether to support Data Binding.  
    // Note that the dataBinding.enabled property is now deprecated.  
    dataBinding = false  
    // Determines whether to generate binder classes for your AIDL files.  
    aidl = true  
    // Determines whether to support RenderScript.  
    renderScript = true  
    // Determines whether to support injecting custom variables into the module’s R class.  
    resValues = true  
    // Determines whether to support shader AOT compilation.  
    shaders = true  
    
    } }

    5
  • Mục không bắt buộc (

    android { // The default value for each feature is shown below. You can change the value to // override the default behavior. buildFeatures {

    // Determines whether to generate a BuildConfig class.  
    buildConfig = true  
    // Determines whether to support View Binding.  
    // Note that the viewBinding.enabled property is now deprecated.  
    viewBinding = false  
    // Determines whether to support Data Binding.  
    // Note that the dataBinding.enabled property is now deprecated.  
    dataBinding = false  
    // Determines whether to generate binder classes for your AIDL files.  
    aidl = true  
    // Determines whether to support RenderScript.  
    renderScript = true  
    // Determines whether to support injecting custom variables into the module’s R class.  
    resValues = true  
    // Determines whether to support shader AOT compilation.  
    shaders = true  
    
    } }

    6,

    android { // The default value for each feature is shown below. You can change the value to // override the default behavior. buildFeatures {

    // Determines whether to generate a BuildConfig class.  
    buildConfig = true  
    // Determines whether to support View Binding.  
    // Note that the viewBinding.enabled property is now deprecated.  
    viewBinding = false  
    // Determines whether to support Data Binding.  
    // Note that the dataBinding.enabled property is now deprecated.  
    dataBinding = false  
    // Determines whether to generate binder classes for your AIDL files.  
    aidl = true  
    // Determines whether to support RenderScript.  
    renderScript = true  
    // Determines whether to support injecting custom variables into the module’s R class.  
    resValues = true  
    // Determines whether to support shader AOT compilation.  
    shaders = true  
    
    } }

    7 và

    android { // The default value for each feature is shown below. You can change the value to // override the default behavior. buildFeatures {

    // Determines whether to generate a BuildConfig class.  
    buildConfig = true  
    // Determines whether to support View Binding.  
    // Note that the viewBinding.enabled property is now deprecated.  
    viewBinding = false  
    // Determines whether to support Data Binding.  
    // Note that the dataBinding.enabled property is now deprecated.  
    dataBinding = false  
    // Determines whether to generate binder classes for your AIDL files.  
    aidl = true  
    // Determines whether to support RenderScript.  
    renderScript = true  
    // Determines whether to support injecting custom variables into the module’s R class.  
    resValues = true  
    // Determines whether to support shader AOT compilation.  
    shaders = true  
    
    } }

  • và một số lớp mới khác hữu ích với các API ở trên
  • Một số mục bổ sung cho

    android { // The default value for each feature is shown below. You can change the value to // override the default behavior. buildFeatures {

    // Determines whether to generate a BuildConfig class.  
    buildConfig = true  
    // Determines whether to support View Binding.  
    // Note that the viewBinding.enabled property is now deprecated.  
    viewBinding = false  
    // Determines whether to support Data Binding.  
    // Note that the dataBinding.enabled property is now deprecated.  
    dataBinding = false  
    // Determines whether to generate binder classes for your AIDL files.  
    aidl = true  
    // Determines whether to support RenderScript.  
    renderScript = true  
    // Determines whether to support injecting custom variables into the module’s R class.  
    resValues = true  
    // Determines whether to support shader AOT compilation.  
    shaders = true  
    
    } }

    9 (các phương thức mới trên

    android { // The default value for each feature is shown below. You can change the value to // override the default behavior. buildFeatures {

    // Determines whether to generate a BuildConfig class.  
    buildConfig = true  
    // Determines whether to support View Binding.  
    // Note that the viewBinding.enabled property is now deprecated.  
    viewBinding = false  
    // Determines whether to support Data Binding.  
    // Note that the dataBinding.enabled property is now deprecated.  
    dataBinding = false  
    // Determines whether to generate binder classes for your AIDL files.  
    aidl = true  
    // Determines whether to support RenderScript.  
    renderScript = true  
    // Determines whether to support injecting custom variables into the module’s R class.  
    resValues = true  
    // Determines whether to support shader AOT compilation.  
    shaders = true  
    
    } }

    0,

    android { // The default value for each feature is shown below. You can change the value to // override the default behavior. buildFeatures {

    // Determines whether to generate a BuildConfig class.  
    buildConfig = true  
    // Determines whether to support View Binding.  
    // Note that the viewBinding.enabled property is now deprecated.  
    viewBinding = false  
    // Determines whether to support Data Binding.  
    // Note that the dataBinding.enabled property is now deprecated.  
    dataBinding = false  
    // Determines whether to generate binder classes for your AIDL files.  
    aidl = true  
    // Determines whether to support RenderScript.  
    renderScript = true  
    // Determines whether to support injecting custom variables into the module’s R class.  
    resValues = true  
    // Determines whether to support shader AOT compilation.  
    shaders = true  
    
    } }

    1 và

    android { // The default value for each feature is shown below. You can change the value to // override the default behavior. buildFeatures {

    // Determines whether to generate a BuildConfig class.  
    buildConfig = true  
    // Determines whether to support View Binding.  
    // Note that the viewBinding.enabled property is now deprecated.  
    viewBinding = false  
    // Determines whether to support Data Binding.  
    // Note that the dataBinding.enabled property is now deprecated.  
    dataBinding = false  
    // Determines whether to generate binder classes for your AIDL files.  
    aidl = true  
    // Determines whether to support RenderScript.  
    renderScript = true  
    // Determines whether to support injecting custom variables into the module’s R class.  
    resValues = true  
    // Determines whether to support shader AOT compilation.  
    shaders = true  
    
    } }

    2)
  • android { // The default value for each feature is shown below. You can change the value to // override the default behavior. buildFeatures {

    // Determines whether to generate a BuildConfig class.  
    buildConfig = true  
    // Determines whether to support View Binding.  
    // Note that the viewBinding.enabled property is now deprecated.  
    viewBinding = false  
    // Determines whether to support Data Binding.  
    // Note that the dataBinding.enabled property is now deprecated.  
    dataBinding = false  
    // Determines whether to generate binder classes for your AIDL files.  
    aidl = true  
    // Determines whether to support RenderScript.  
    renderScript = true  
    // Determines whether to support injecting custom variables into the module’s R class.  
    resValues = true  
    // Determines whether to support shader AOT compilation.  
    shaders = true  
    
    } }

    3 (có bản sửa lỗi cho Android 5.0)

Để hỗ trợ các API ngôn ngữ này, D8 biên dịch một tệp DEX thư viện riêng có chứa phương thức triển khai các API còn thiếu và đưa vào ứng dụng. Quy trình đơn giản hoá sẽ ghi lại mã ứng dụng để chuyển sang sử dụng thư viện này trong thời gian chạy.

Để bật tính năng hỗ trợ cho các API ngôn ngữ này, hãy đưa nội dung sau đây vào tệp

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

4 của mô-đun ứng dụng:

`android { defaultConfig {

// Required when setting minSdkVersion to 20 or lower
multiDexEnabled true
}

compileOptions {

// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
} }

`

dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.4' }

`android { defaultConfig {

// Required when setting minSdkVersion to 20 or lower
multiDexEnabled = true
}

compileOptions {

// Flag to enable support for the new language APIs
isCoreLibraryDesugaringEnabled = true
// Sets Java compatibility to Java 8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
} }

`

dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.0.4") }

Xin lưu ý rằng bạn cũng cần đưa đoạn mã trên vào tệp

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

4 của mô-đun thư viện nếu

  • Các bài kiểm thử đo lường của mô-đun thư viện dùng các API ngôn ngữ này (trực tiếp hoặc thông qua mô-đun thư viện hay các phần phụ thuộc của mô-đun này). Mục đích của việc này là cung cấp các API còn thiếu cho tệp APK kiểm thử được đo lường.
  • Bạn muốn chạy riêng công cụ tìm lỗi mã nguồn trên mô-đun thư viện. Việc này giúp công cụ tìm lỗi mã nguồn nhận ra cách sử dụng hợp lệ các API ngôn ngữ và tránh báo cáo các cảnh báo sai.

Chế độ mới giúp bật hoặc tắt tính năng xây dựng

Trình bổ trợ Android cho Gradle 4.0.0 giới thiệu một cách mới để điều khiển các tính năng bản dựng mà bạn muốn bật và vô hiệu hoá, chẳng hạn như Liên kết khung hiển thị (View Binding) và Liên kết dữ liệu (Data Binding). Theo mặc định, các tính năng mới được thêm vào sẽ bị vô hiệu hoá. Sau đó, bạn có thể sử dụng khối

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

6 để chỉ bật các tính năng mình muốn và giúp tối ưu hoá hiệu suất bản dựng cho dự án. Bạn có thể thiết lập chế độ cho mỗi mô-đun trong tệp

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

4 ở cấp mô-đun như sau:

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}
android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

Bạn cũng có thể chỉ định chế độ cài đặt mặc định cho các tính năng này trên tất cả mô-đun trong dự án bằng cách đưa một hoặc nhiều nội dung sau vào tệp

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

8 của dự án như bên dưới. Lưu ý là bạn vẫn có thể sử dụng khối

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

6 trong tệp

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

4 ở cấp mô-đun để ghi đè lên chế độ cài đặt mặc định trên toàn dự án.

android.defaults.buildfeatures.buildconfig=true
android.defaults.buildfeatures.aidl=true
android.defaults.buildfeatures.renderscript=true
android.defaults.buildfeatures.resvalues=true
android.defaults.buildfeatures.shaders=true

Các phần phụ thuộc có tính năng liên quan với nhau

Trong các phiên bản trước của trình bổ trợ Android cho Gradle, tất cả mô-đun tính năng chỉ dựa vào mô-đun cơ sở của ứng dụng. Giờ đây, khi sử dụng trình bổ trợ Android cho Gradle 4.0.0, bạn có thể thêm mô-đun tính năng phụ thuộc một mô-đun tính năng khác. Điều đó có nghĩa là một tính năng của

android.defaults.buildfeatures.buildconfig=true
android.defaults.buildfeatures.aidl=true
android.defaults.buildfeatures.renderscript=true
android.defaults.buildfeatures.resvalues=true
android.defaults.buildfeatures.shaders=true

1 có thể phụ thuộc vào tính năng của

android.defaults.buildfeatures.buildconfig=true
android.defaults.buildfeatures.aidl=true
android.defaults.buildfeatures.renderscript=true
android.defaults.buildfeatures.resvalues=true
android.defaults.buildfeatures.shaders=true

2. Tính năng này lại phụ thuộc vào mô-đun cơ sở, theo minh hoạ trong hình dưới đây.

Lỗi phân tích cú pháp trên android 4.0.4 năm 2024

Mô-đun tính năng

android.defaults.buildfeatures.buildconfig=true
android.defaults.buildfeatures.aidl=true
android.defaults.buildfeatures.renderscript=true
android.defaults.buildfeatures.resvalues=true
android.defaults.buildfeatures.shaders=true

1 phụ thuộc vào tính năng

android.defaults.buildfeatures.buildconfig=true
android.defaults.buildfeatures.aidl=true
android.defaults.buildfeatures.renderscript=true
android.defaults.buildfeatures.resvalues=true
android.defaults.buildfeatures.shaders=true

2. Tính năng này lại phụ thuộc vào mô-đun

android.defaults.buildfeatures.buildconfig=true
android.defaults.buildfeatures.aidl=true
android.defaults.buildfeatures.renderscript=true
android.defaults.buildfeatures.resvalues=true
android.defaults.buildfeatures.shaders=true

5 cơ sở.

Điều này có nghĩa là khi ứng dụng yêu cầu tải một mô-đun tính năng xuống, ứng dụng cũng sẽ tải các mô-đun tính năng khác mà nó phụ thuộc vào. Sau khi tạo mô-đun tính năngcho ứng dụng, bạn có thể khai báo phần phụ thuộc có tính năng liên quan đến nhau trên tệp

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

4 của mô-đun. Ví dụ: mô-đun

android.defaults.buildfeatures.buildconfig=true
android.defaults.buildfeatures.aidl=true
android.defaults.buildfeatures.renderscript=true
android.defaults.buildfeatures.resvalues=true
android.defaults.buildfeatures.shaders=true

1 khai báo phần phụ thuộc trên

android.defaults.buildfeatures.buildconfig=true
android.defaults.buildfeatures.aidl=true
android.defaults.buildfeatures.renderscript=true
android.defaults.buildfeatures.resvalues=true
android.defaults.buildfeatures.shaders=true

2 như sau:

// In the build.gradle file of the ':video' module.
dependencies {
  // All feature modules must declare a dependency
  // on the base module.
  implementation project(':app')
  // Declares that this module also depends on the 'camera'
  // feature module.
  implementation project(':camera')
  ...
}
// In the build.gradle file of the ':video' module.
dependencies {
    // All feature modules must declare a dependency
    // on the base module.
    implementation(project(":app"))
    // Declares that this module also depends on the 'camera'
    // feature module.
    implementation(project(":camera"))
    ...
}

Ngoài ra, bạn nên bật tính năng phần phụ thuộc có tính năng liên quan với nhau trong Android Studio (ví dụ: để hỗ trợ tính năng này khi chỉnh sửa cấu hình Chạy) bằng cách nhấp vào Trợ giúp > Chỉnh sửa chế độ máy ảo tuỳ chỉnh (Help > Edit Custom VM Options) trên thanh trình đơn rồi thêm nội dung sau:

-Drundebug.feature.on.feature=true

Siêu dữ liệu của phần phụ thuộc

Khi xây dựng ứng dụng bằng trình bổ trợ Android cho Gradle 4.0.0 trở lên, trình bổ trợ sẽ tích hợp siêu dữ liệu mô tả các phần phụ thuộc được biên dịch thành ứng dụng. Khi bạn tải ứng dụng lên, Play Console sẽ kiểm tra siêu dữ liệu này để mang lại cho bạn những lợi ích sau:

  • Nhận cảnh báo về các vấn đề đã biết liên quan đến SDK và các phần phụ thuộc ứng dụng sử dụng
  • Nhận ý kiến phản hồi hữu ích để giải quyết những vấn đề đó

Dữ liệu được một khoá ký Google Play nén, mã hoá và lưu trữ trong khối ký của ứng dụng phát hành. Tuy nhiên, bạn có thể tự kiểm tra siêu dữ liệu trong các tệp bản dựng trung gian cục bộ trong thư mục sau:

android.defaults.buildfeatures.buildconfig=true
android.defaults.buildfeatures.aidl=true
android.defaults.buildfeatures.renderscript=true
android.defaults.buildfeatures.resvalues=true
android.defaults.buildfeatures.shaders=true

9.

Nếu không muốn chia sẻ thông tin này, bạn có thể chọn không thực hiện bằng cách đưa nội dung sau vào tệp

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

4 của mô-đun:

android {
  dependenciesInfo {
      // Disables dependency metadata when building APKs.
      includeInApk = false
      // Disables dependency metadata when building Android App Bundles.
      includeInBundle = false
  }
}
android {
  dependenciesInfo {
      // Disables dependency metadata when building APKs.
      includeInApk = false
      // Disables dependency metadata when building Android App Bundles.
      includeInBundle = false
  }
}

Nhập thư viện gốc từ các phần phụ thuộc AAR

Giờ đây, bạn có thể nhập thư viện C/C++ từ các phần phụ thuộc AAR của ứng dụng. Khi bạn làm theo các bước cấu hình được mô tả dưới đây, Gradle sẽ tự động cung cấp những thư viện gốc này để sử dụng với hệ thống bản dựng gốc bên ngoài, chẳng hạn như CMake. Xin lưu ý rằng Gradle chỉ cung cấp những thư viện này cho bản dựng; bạn vẫn phải định cấu hình các tập lệnh bản dựng để sử dụng các thư viện đó.

Các thư viện được xuất bằng định dạng gói Prefab.

Mỗi phần phụ thuộc có thể hiển thị tối đa một gói Profab (bao gồm một hoặc nhiều mô-đun). Mô-đun Prefab là một thư viện, có thể là một thư viện chia sẻ, tĩnh hoặc chỉ có tiêu đề.

Thông thường, tên gói khớp với tên cấu phần phần mềm Maven và tên mô-đun khớp với tên thư viện. Tuy nhiên, điều này không phải lúc nào cũng đúng. Vì bạn cần biết tên gói và mô-đun của các thư viện, bạn có thể cần tham khảo tài liệu về phần phụ thuộc để xác định các tên đó.

Định cấu hình hệ thống bản dựng gốc bên ngoài

Để xem các bước bạn cần thực hiện, hãy làm theo các bước dưới đây đối với hệ thống bản dựng gốc bên ngoài bạn định sử dụng.

Mỗi phần phụ thuộc AAR của ứng dụng có chứa mã gốc sẽ cho thấy một tệp

// In the build.gradle file of the ':video' module.
dependencies {
  // All feature modules must declare a dependency
  // on the base module.
  implementation project(':app')
  // Declares that this module also depends on the 'camera'
  // feature module.
  implementation project(':camera')
  ...
}

1 bạn cần nhập vào dự án ndk-build. Bạn nhập tệp này bằng lệnh . Thao tác này sẽ tìm kiếm các đường dẫn mà bạn chỉ định bằng cách sử dụng thuộc tính

// In the build.gradle file of the ':video' module.
dependencies {
  // All feature modules must declare a dependency
  // on the base module.
  implementation project(':app')
  // Declares that this module also depends on the 'camera'
  // feature module.
  implementation project(':camera')
  ...
}

3 trong dự án ndk-build. Ví dụ: nếu ứng dụng xác định

// In the build.gradle file of the ':video' module.
dependencies {
  // All feature modules must declare a dependency
  // on the base module.
  implementation project(':app')
  // Declares that this module also depends on the 'camera'
  // feature module.
  implementation project(':camera')
  ...
}

4 và phần phụ thuộc này sử dụng lệnh curl, bạn cần thêm các nội dung sau đây trong tệp Android.mk:

  1. Đối với CMake: android {

    defaultConfig {

    // Required when setting minSdkVersion to 20 or lower  
    multiDexEnabled = true  
    
    } compileOptions {
    // Flag to enable support for the new language APIs  
    isCoreLibraryDesugaringEnabled = true  
    // Sets Java compatibility to Java 8  
    sourceCompatibility = JavaVersion.VERSION_1_8  
    targetCompatibility = JavaVersion.VERSION_1_8  
    
    } }

    dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.0.4") } 0
  2. Đối với

    // In the build.gradle file of the ':video' module. dependencies { // All feature modules must declare a dependency // on the base module. implementation project(':app') // Declares that this module also depends on the 'camera' // feature module. implementation project(':camera') ... }

    5:

    android {

    defaultConfig {

    // Required when setting minSdkVersion to 20 or lower  
    multiDexEnabled = true  
    
    } compileOptions {
    // Flag to enable support for the new language APIs  
    isCoreLibraryDesugaringEnabled = true  
    // Sets Java compatibility to Java 8  
    sourceCompatibility = JavaVersion.VERSION_1_8  
    targetCompatibility = JavaVersion.VERSION_1_8  
    
    } }

    dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.0.4") } 1

Các phần phụ thuộc gốc có trong AAR sẽ hiện với dự án CMake thông qua biến CMAKE_FIND_ROOT_PATH {: .external}. Giá trị này sẽ được Gradle thiết lập tự động khi CMake được gọi. Vì vậy, nếu hệ thống bản dựng sửa đổi, hãy nhớ thêm vào thay vì chỉ định biến trên.

Mỗi phần phụ thuộc sẽ hiện một {: .external} với bản dựng CMake, mà bạn nhập bằng lệnh

// In the build.gradle file of the ':video' module.
dependencies {
  // All feature modules must declare a dependency
  // on the base module.
  implementation project(':app')
  // Declares that this module also depends on the 'camera'
  // feature module.
  implementation project(':camera')
  ...
}

6{: .external} . Lệnh này tìm kiếm các gói tệp cấu hình khớp với tên và phiên bản gói đã nêu và cho thấy các mục tiêu mà hệ thống xác định sẽ được dùng trong bản dựng. Ví dụ: nếu ứng dụng của bạn xác định

// In the build.gradle file of the ':video' module.
dependencies {
  // All feature modules must declare a dependency
  // on the base module.
  implementation project(':app')
  // Declares that this module also depends on the 'camera'
  // feature module.
  implementation project(':camera')
  ...
}

4 và phần phụ thuộc sử dụng lệnh curl, bạn nên đưa những nội dung sau vào tệp

// In the build.gradle file of the ':video' module.
dependencies {
  // All feature modules must declare a dependency
  // on the base module.
  implementation project(':app')
  // Declares that this module also depends on the 'camera'
  // feature module.
  implementation project(':camera')
  ...
}

8:

`android { defaultConfig {

// Required when setting minSdkVersion to 20 or lower
multiDexEnabled = true
}

compileOptions {

// Flag to enable support for the new language APIs
isCoreLibraryDesugaringEnabled = true
// Sets Java compatibility to Java 8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
} }

`

dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.0.4") }

2

Giờ đây, bạn có thể chỉ định

// In the build.gradle file of the ':video' module.
dependencies {
  // All feature modules must declare a dependency
  // on the base module.
  implementation project(':app')
  // Declares that this module also depends on the 'camera'
  // feature module.
  implementation project(':camera')
  ...
}

9 trong

// In the build.gradle file of the ':video' module.
dependencies {
    // All feature modules must declare a dependency
    // on the base module.
    implementation(project(":app"))
    // Declares that this module also depends on the 'camera'
    // feature module.
    implementation(project(":camera"))
    ...
}

0. Khi bạn xây dựng dự án, hệ thống bản dựng gốc bên ngoài sẽ tự động liên kết

// In the build.gradle file of the ':video' module.
dependencies {
  // All feature modules must declare a dependency
  // on the base module.
  implementation project(':app')
  // Declares that this module also depends on the 'camera'
  // feature module.
  implementation project(':camera')
  ...
}

4 với

// In the build.gradle file of the ':video' module.
dependencies {
    // All feature modules must declare a dependency
    // on the base module.
    implementation(project(":app"))
    // Declares that this module also depends on the 'camera'
    // feature module.
    implementation(project(":camera"))
    ...
}

2 và các gói

// In the build.gradle file of the ':video' module.
dependencies {
    // All feature modules must declare a dependency
    // on the base module.
    implementation(project(":app"))
    // Declares that this module also depends on the 'camera'
    // feature module.
    implementation(project(":camera"))
    ...
}

2 trong tệp APK hoặc gói ứng dụng. Để biết thêm thông tin, hãy tham khảo curl prefab mẫu{:.external}.

Thay đổi về hành vi

Khi sử dụng phiên bản trình bổ trợ này, bạn có thể gặp phải các thay đổi hành vi sau.

Cập nhật cấu hình ký tên bằng v1/v2

Hành vi đối với cấu hình ký tên ứng dụng trong khối

// In the build.gradle file of the ':video' module.
dependencies {
    // All feature modules must declare a dependency
    // on the base module.
    implementation(project(":app"))
    // Declares that this module also depends on the 'camera'
    // feature module.
    implementation(project(":camera"))
    ...
}

4 đã thay đổi thành:

Ký bằng v1

  • Nếu

    // In the build.gradle file of the ':video' module. dependencies {

    // All feature modules must declare a dependency  
    // on the base module.  
    implementation(project(":app"))  
    // Declares that this module also depends on the 'camera'  
    // feature module.  
    implementation(project(":camera"))  
    ...  
    
    }

    5 được bật một cách rõ ràng, AGP sẽ thực hiện ký ứng dụng bằng v1.
  • Nếu

    // In the build.gradle file of the ':video' module. dependencies {

    // All feature modules must declare a dependency  
    // on the base module.  
    implementation(project(":app"))  
    // Declares that this module also depends on the 'camera'  
    // feature module.  
    implementation(project(":camera"))  
    ...  
    
    }

    5 bị người dùng vô hiệu hoá một cách rõ ràng, tính năng ký ứng dụng bằng v1 sẽ không được thực hiện.
  • Nếu người dùng chưa bật tính năng ký bằng v1 một cách rõ ràng, tính năng này có thể bị vô hiệu hoá tự động dựa trên

    // In the build.gradle file of the ':video' module. dependencies {

    // All feature modules must declare a dependency  
    // on the base module.  
    implementation(project(":app"))  
    // Declares that this module also depends on the 'camera'  
    // feature module.  
    implementation(project(":camera"))  
    ...  
    
    }

    7 và

    // In the build.gradle file of the ':video' module. dependencies {

    // All feature modules must declare a dependency  
    // on the base module.  
    implementation(project(":app"))  
    // Declares that this module also depends on the 'camera'  
    // feature module.  
    implementation(project(":camera"))  
    ...  
    
    }

    8.

Ký bằng v2

  • Nếu

    // In the build.gradle file of the ':video' module. dependencies {

    // All feature modules must declare a dependency  
    // on the base module.  
    implementation(project(":app"))  
    // Declares that this module also depends on the 'camera'  
    // feature module.  
    implementation(project(":camera"))  
    ...  
    
    }

    9 được bật một cách rõ ràng, AGP sẽ thực hiện ký ứng dụng bằng v2.
  • Nếu

    // In the build.gradle file of the ':video' module. dependencies {

    // All feature modules must declare a dependency  
    // on the base module.  
    implementation(project(":app"))  
    // Declares that this module also depends on the 'camera'  
    // feature module.  
    implementation(project(":camera"))  
    ...  
    
    }

    9 bị người dùng vô hiệu hoá một cách rõ ràng, tính năng ký ứng dụng bằng v2 sẽ không được thực hiện.
  • Nếu người dùng chưa bật tính năng ký bằng v2 một cách rõ ràng, tính năng này có thể bị vô hiệu hoá tự động dựa trên

    // In the build.gradle file of the ':video' module. dependencies {

    // All feature modules must declare a dependency  
    // on the base module.  
    implementation(project(":app"))  
    // Declares that this module also depends on the 'camera'  
    // feature module.  
    implementation(project(":camera"))  
    ...  
    
    }

    8.

Những thay đổi này cho phép AGP tối ưu hoá bản dựng bằng cách vô hiệu hoá cơ chế ký dựa trên việc người dùng có bật các cờ này một cách rõ ràng hay không. Trước bản phát hành này,

-Drundebug.feature.on.feature=true

2 có thể bị vô hiệu hoá ngay cả khi được bật một cách rõ ràng. Điều này có thể gây nhầm lẫn.

Xoá trình bổ trợ Android cho Gradle

-Drundebug.feature.on.feature=true

3 và

-Drundebug.feature.on.feature=true

4

Trình bổ trợ Android cho Gradle 3.6.0 đã ngừng sử dụng trình bổ trợ Tính năng (

-Drundebug.feature.on.feature=true

  1. và trình bổ trợ Ứng dụng tức thì (

-Drundebug.feature.on.feature=true

  1. để ưu tiên sử dụng trình bổ trợ Tính năng động (

-Drundebug.feature.on.feature=true

  1. nhằm tạo và đóng gói các ứng dụng tức thì bằng Android App Bundle.

Trong trình bổ trợ Android cho Gradle 4.0.0 trở lên, những trình bổ trợ bị ngừng sử dụng này sẽ bị xoá hoàn toàn. Do đó, để sử dụng trình bổ trợ Android cho Gradle mới nhất, bạn cần di chuyển ứng dụng tức thì để hỗ trợ Android App Bundle. Bằng cách di chuyển các ứng dụng tức thì, bạn có thể tận dụng những lợi ích của gói ứng dụng và đơn giản hoá thiết kế mô-đun của ứng dụng.

Lưu ý: Để mở các dự án sử dụng trình bổ trợ đã bị xoá trong Android Studio 4.0 trở lên, dự án đó phải sử dụng trình bổ trợ Android cho Gradle 3.6.0 trở xuống.

Xoá tính năng xử lý chú giải riêng

Khả năng tách riêng xử lý chú giải thành một tác vụ chuyên biệt đã bị xoá. Tính năng này dùng để duy trì quá trình biên dịch Java gia tăng khi các trình xử lý chú giải không gia tăng được dùng trong các dự án chỉ dành cho Java. Tính năng này đã được bật bằng cách thiết lập

-Drundebug.feature.on.feature=true

8 thành

-Drundebug.feature.on.feature=true

9 trong tệp

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

8, tuy nhiên không còn hoạt động nữa.

Thay vào đó, bạn nên chuyển sang để cải thiện hiệu suất bản dựng.

Ngừng sử dụng includeCompileClasspath

Trình bổ trợ Android cho Gradle không còn kiểm tra hoặc tích hợp những trình xử lý chú giải mà bạn khai báo trên classpath biên dịch. Đồng thời, thuộc tính DSL

android {
  dependenciesInfo {
      // Disables dependency metadata when building APKs.
      includeInApk = false
      // Disables dependency metadata when building Android App Bundles.
      includeInBundle = false
  }
}

1 không còn gây ảnh hưởng nữa. Nếu đưa trình xử lý chú giải vào classpath biên dịch, bạn có thể gặp lỗi sau:

`android { defaultConfig {

// Required when setting minSdkVersion to 20 or lower
multiDexEnabled = true
}

compileOptions {

// Flag to enable support for the new language APIs
isCoreLibraryDesugaringEnabled = true
// Sets Java compatibility to Java 8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
} }

`

dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.0.4") }

3

Để giải quyết vấn đề này, bạn phải đưa trình xử lý chú giải vào tệp

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

4 bằng cấu hình phần phụ thuộc

android {
  dependenciesInfo {
      // Disables dependency metadata when building APKs.
      includeInApk = false
      // Disables dependency metadata when building Android App Bundles.
      includeInBundle = false
  }
}

3. Để tìm hiểu thêm, hãy đọc phần .

Tự động đóng gói phần phụ thuộc tạo sẵn mà CMake sử dụng

Đối với các phiên bản trước của trình bổ trợ Android cho Gradle, bạn cần phải dùng

android {
  dependenciesInfo {
      // Disables dependency metadata when building APKs.
      includeInApk = false
      // Disables dependency metadata when building Android App Bundles.
      includeInBundle = false
  }
}

4 để đóng gói rõ ràng mọi thư viện tạo sẵn mà hệ thống xây dựng gốc bên ngoài CMake sử dụng. Các thư viện có thể nằm trong thư mục

android {
  dependenciesInfo {
      // Disables dependency metadata when building APKs.
      includeInApk = false
      // Disables dependency metadata when building Android App Bundles.
      includeInBundle = false
  }
}

5 của mô-đun hoặc có thể trong một số thư mục khác được định cấu hình trong tệp

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

4:

`android { defaultConfig {

// Required when setting minSdkVersion to 20 or lower
multiDexEnabled = true
}

compileOptions {

// Flag to enable support for the new language APIs
isCoreLibraryDesugaringEnabled = true
// Sets Java compatibility to Java 8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
} }

`

dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.0.4") }

4

`android { defaultConfig {

// Required when setting minSdkVersion to 20 or lower
multiDexEnabled = true
}

compileOptions {

// Flag to enable support for the new language APIs
isCoreLibraryDesugaringEnabled = true
// Sets Java compatibility to Java 8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
} }

`

dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.0.4") }

5

Với trình bổ trợ Android cho Gradle 4.0, cấu hình trên không còn cần thiết và sẽ gây ra lỗi bản dựng:

`android { defaultConfig {

// Required when setting minSdkVersion to 20 or lower
multiDexEnabled = true
}

compileOptions {

// Flag to enable support for the new language APIs
isCoreLibraryDesugaringEnabled = true
// Sets Java compatibility to Java 8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
} }

`

dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.0.4") }

6

Bản dựng gốc bên ngoài hiện tự động đóng gói các thư viện đó. Vì vậy, việc đóng gói rõ ràng thư viện bằng

android {
  dependenciesInfo {
      // Disables dependency metadata when building APKs.
      includeInApk = false
      // Disables dependency metadata when building Android App Bundles.
      includeInBundle = false
  }
}

4 sẽ dẫn đến việc trùng lặp. Để tránh lỗi bản dựng, hãy di chuyển thư viện tạo sẵn đến một vị trí bên ngoài

android {
  dependenciesInfo {
      // Disables dependency metadata when building APKs.
      includeInApk = false
      // Disables dependency metadata when building Android App Bundles.
      includeInBundle = false
  }
}

4 hoặc xoá cấu hình

android {
  dependenciesInfo {
      // Disables dependency metadata when building APKs.
      includeInApk = false
      // Disables dependency metadata when building Android App Bundles.
      includeInBundle = false
  }
}

4 khỏi tệp

android {
  // The default value for each feature is shown below. You can change the value to
  // override the default behavior.
  buildFeatures {
    // Determines whether to generate a BuildConfig class.
    buildConfig = true
    // Determines whether to support View Binding.
    // Note that the viewBinding.enabled property is now deprecated.
    viewBinding = false
    // Determines whether to support Data Binding.
    // Note that the dataBinding.enabled property is now deprecated.
    dataBinding = false
    // Determines whether to generate binder classes for your AIDL files.
    aidl = true
    // Determines whether to support RenderScript.
    renderScript = true
    // Determines whether to support injecting custom variables into the module’s R class.
    resValues = true
    // Determines whether to support shader AOT compilation.
    shaders = true
  }
}

4.

Vấn đề đã biết

Phần này mô tả các sự cố đã biết tồn tại trong trình bổ trợ Android cho Gradle 4.0.0.

Điều kiện tranh đấu trong cơ chế trình chạy Gradle

Các thay đổi trong trình bổ trợ Android cho Gradle 4.0 có thể kích hoạt điều kiện tranh đấu trong Gradle khi chạy với

android {
  dependenciesInfo {
      // Disables dependency metadata when building APKs.
      includeInApk = false
      // Disables dependency metadata when building Android App Bundles.
      includeInBundle = false
  }
}

1 và các phiên bản của Gradle 6.3 trở xuống. Điều này khiến các bản dựng bị treo sau khi hoàn tất.