{"id":119956,"date":"2026-10-30T19:25:01","date_gmt":"2026-10-30T11:25:01","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/119956.html"},"modified":"2026-10-30T19:25:01","modified_gmt":"2026-10-30T11:25:01","slug":"cmp-for-openharmony-%e5%ae%9e%e6%88%98%ef%bc%9acoil-%e5%9b%be%e7%89%87%e5%8a%a0%e8%bd%bd%e5%ba%93%e9%b8%bf%e8%92%99%e5%8c%96%e4%bd%bf%e7%94%a8%e5%bf%83%e5%be%97","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/119956.html","title":{"rendered":"CMP for OpenHarmony \u5b9e\u6218\uff1aCoil \u56fe\u7247\u52a0\u8f7d\u5e93\u9e3f\u8499\u5316\u4f7f\u7528\u5fc3\u5f97"},"content":{"rendered":"<p>\u6846\u67b6&#xff1a;Compose Multiplatform v1.9.2-1.0.0 &#043; OpenHarmony SDK 6.0.0(20) \u5e93\u540d\u79f0&#xff1a;Coil 3.3.0&#xff08;Compose Multiplatform \u56fe\u7247\u52a0\u8f7d\u5e93&#xff09; \u9e3f\u8499\u9002\u914d\u4ed3\u5e93&#xff1a;CPF-KMP-CMP\/coil \u9002\u914d\u5206\u652f&#xff1a;main-3.3.0-OH&#xff08;\u9e3f\u8499\u5b9a\u5236\u7248&#xff09; \u7248\u672c&#xff1a;v3.3.0-1.0.0 Maven \u5750\u6807&#xff1a;io.coil-kt.coil3:coil-compose:3.3.0&#xff08;\u914d\u5408 coil-network-ktor3&#xff09;<\/p>\n<hr \/>\n<h3>\u6458\u8981<\/h3>\n<p>Coil \u662f Compose Multiplatform \u751f\u6001\u6700\u6d41\u884c\u7684\u56fe\u7247\u52a0\u8f7d\u5e93&#xff0c;\u800c CPF-KMP-CMP \u793e\u533a\u5df2\u4e3a\u5b83\u5b8c\u6210\u4e86 ohosArm64 target \u7684\u6df1\u5ea6\u9002\u914d\u3002\u672c\u6587\u57fa\u4e8e\u5bf9 CPF-KMP-CMP\/coil&#xff08;\u5206\u652f main-3.3.0-OH&#xff0c;tag v3.3.0-1.0.0&#xff09;\u4e0e CPF-KMP-CMP\/compose-multiplatform \u4e24\u4e2a\u4ed3\u5e93\u7684\u6e90\u7801\u63a2\u67e5&#xff0c;\u7cfb\u7edf\u68b3\u7406 Coil \u5728\u9e3f\u8499 CMP \u9879\u76ee\u4e2d\u7684\u5b8c\u6574\u843d\u5730\u8def\u5f84&#xff1a;\u4ece\u5f00\u53d1\u73af\u5883\u4e0e\u7248\u672c\u53f7\u5168\u666f\u3001CPF \u4e09\u6e90 Nexus \u4ed3\u5e93\u914d\u7f6e\u3001ohosArm64 target \u4e0e linkerOpts \u9010\u884c\u89e3\u6790&#xff0c;\u5230\u4e09\u9879\u9e3f\u8499\u7279\u6709\u673a\u5236\u2014\u2014OhosNativeDmaDecoder \u786c\u4ef6\u52a0\u901f\u89e3\u7801\u3001ServiceLoader \u2192 &#064;EagerInitialization \u81ea\u52a8\u6ce8\u518c\u3001coil-gif \u539f\u751f HEIF \u52a8\u753b\u89e3\u7801\u3002\u6587\u4e2d\u7ed9\u51fa\u53ef\u76f4\u63a5\u590d\u7528\u7684 settings.gradle.kts\u3001libs.versions.toml\u3001build.gradle.kts \u914d\u7f6e\u4e0e AsyncImage\u3001LazyColumn\u3001Transformation\u3001\u7f13\u5b58\u7b56\u7565\u7b49\u4f7f\u7528\u6848\u4f8b&#xff0c;\u5e76\u9644\u6784\u5efa\u65e5\u5fd7\u5173\u952e\u5b57\u3001\u7f51\u7edc\u6743\u9650\u914d\u7f6e\u3001\u5e38\u89c1\u9519\u8bef\u6392\u67e5\u8868\u4e0e 10 \u6761 FAQ&#xff0c;\u5e2e\u52a9\u4f60\u628a Coil \u771f\u6b63\u8dd1\u901a\u5728\u9e3f\u8499\u771f\u673a\u4e0a\u3002<\/p>\n<h3>\u76ee\u5f55<\/h3>\n<ul>\n<li>\u4e00\u3001\u4e3a\u4ec0\u4e48\u9009 Coil \u4f5c\u4e3a CMP \u9e3f\u8499\u7b2c\u4e00\u7bc7\u6587\u7ae0<\/li>\n<li>\u4e8c\u3001\u5f00\u53d1\u73af\u5883\n<ul>\n<li>\u73af\u5883\u642d\u5efa\u6307\u5f15<\/li>\n<\/ul>\n<\/li>\n<li>\u4e09\u3001Coil \u9002\u914d\u72b6\u6001 &amp; \u7248\u672c\u5bf9\u6bd4\n<ul>\n<li>3.1 CPF-KMP-CMP \u9e3f\u8499\u5b9a\u5236\u7248 vs \u4e0a\u6e38 Maven Central<\/li>\n<li>3.2 \u7248\u672c\u53f7\u5168\u666f&#xff08;\u6765\u81ea coil-oh \u7684 gradle\/libs.versions.toml&#xff09;<\/li>\n<li>3.3 CPF \u4ed3\u5e93\u771f\u5b9e Maven \u914d\u7f6e&#xff08;\u6765\u81ea build.gradle.kts&#xff09;<\/li>\n<li>3.4 \u4f9d\u8d56\u94fe\u5168\u666f&#xff08;\u57fa\u4e8e\u6e90\u7801\u5206\u6790&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\u56db\u3001\u5982\u4f55\u5728\u9e3f\u8499 CMP \u9879\u76ee\u4e2d\u5f15\u5165 Coil\n<ul>\n<li>4.1 \u9879\u76ee\u7ed3\u6784<\/li>\n<li>4.2 settings.gradle.kts \u4ed3\u5e93\u914d\u7f6e<\/li>\n<li>4.3 libs.versions.toml \u7248\u672c\u76ee\u5f55<\/li>\n<li>4.4 ohosArm64 target &#043; linkerOpts \u8be6\u89e3<\/li>\n<li>4.5 \u9e3f\u8499\u7279\u6709\u673a\u5236\u4e00&#xff1a;OhosNativeDmaDecoder \u6df1\u5ea6\u89e3\u6790<\/li>\n<li>4.6 \u9e3f\u8499\u7279\u6709\u673a\u5236\u4e8c&#xff1a;ServiceLoader \u2192 &#064;EagerInitialization<\/li>\n<li>4.7 \u9e3f\u8499\u7279\u6709\u673a\u5236\u4e09&#xff1a;coil-gif \u7684\u539f\u751f HEIF \u52a8\u753b<\/li>\n<\/ul>\n<\/li>\n<li>\u4e94\u3001Coil \u5728\u9e3f\u8499\u4e0a\u7684\u4f7f\u7528\u6848\u4f8b\n<ul>\n<li>5.1 \u57fa\u7840&#xff1a;AsyncImage \u52a0\u8f7d\u7f51\u7edc\u56fe\u7247<\/li>\n<li>5.2 \u8fdb\u9636&#xff1a;LazyColumn \u56fe\u7247\u5217\u8868<\/li>\n<li>5.3 \u5f00\u542f DMA \u52a0\u901f\u89e3\u7801<\/li>\n<li>5.4 \u81ea\u5b9a\u4e49 Transformation&#xff1a;\u5706\u5f62\u88c1\u526a &#043; \u6a21\u7cca<\/li>\n<li>5.5 ImageLoader \u7f13\u5b58\u7b56\u7565\u6df1\u5ea6\u914d\u7f6e<\/li>\n<li>5.6 Compose \u91cd\u7ec4\u5b89\u5168&#xff1a;ImageRequest \u7528 remember \u5305\u88f9<\/li>\n<li>5.7 \u56fe\u7247\u683c\u5f0f\u652f\u6301\u5168\u666f<\/li>\n<\/ul>\n<\/li>\n<li>\u516d\u3001\u7f16\u8bd1\u6784\u5efa\u4e0e\u771f\u673a\u8fd0\u884c\n<ul>\n<li>6.1 DevEco Studio 26 \u7248\u91cc\u7684\u6784\u5efa<\/li>\n<li>6.2 compose-multiplatform \u6784\u5efa\u65e5\u5fd7\u5173\u952e\u5b57<\/li>\n<li>6.3 \u9e3f\u8499\u5bbf\u4e3b\u7f51\u7edc\u6743\u9650&#xff08;\u5fc5\u914d&#xff01;&#xff09;<\/li>\n<li>6.4 \u5e38\u89c1\u6784\u5efa\u9519\u8bef\u6392\u67e5<\/li>\n<\/ul>\n<\/li>\n<li>\u4e03\u3001\u6e90\u7801\u63a2\u67e5&#xff1a;ohosArm64Main \u76ee\u5f55\u5168\u89e3\n<ul>\n<li>coil-oh \u7684 hierarchy template \u8bbe\u8ba1\u89e3\u8bfb<\/li>\n<\/ul>\n<\/li>\n<li>\u516b\u3001FAQ<\/li>\n<li>\u4e5d\u3001\u793e\u533a\u5f15\u5bfc<\/li>\n<\/ul>\n<h3>\u4e00\u3001\u4e3a\u4ec0\u4e48\u9009 Coil \u4f5c\u4e3a CMP \u9e3f\u8499\u7b2c\u4e00\u7bc7\u6587\u7ae0<\/h3>\n<p>Coil \u662f Compose Multiplatform \u751f\u6001\u6700\u6d41\u884c\u7684\u56fe\u7247\u52a0\u8f7d\u5e93\u2014\u2014Android \u5f00\u53d1\u8005\u51e0\u4e4e\u90fd\u7528\u8fc7&#xff08;Coil &#061; Co-routine &#043; Image Loader&#xff09;\u3002\u5728 CMP \u8de8\u5e73\u53f0\u573a\u666f\u4e0b&#xff0c;\u5b83\u4e00\u5957\u4ee3\u7801\u8dd1 Android\/iOS\/\u9e3f\u8499\/Desktop&#xff0c;\u5e95\u5c42\u7528 Kotlin\/Native &#043; Skia \u6e32\u67d3&#xff0c;\u4e0d\u4f9d\u8d56\u5e73\u53f0\u539f\u751f\u56fe\u7247\u52a0\u8f7d API\u3002<\/p>\n<p>CPF-KMP-CMP \u793e\u533a\u5df2\u7ecf\u5b8c\u6210\u4e86 ohosArm64 target \u7684\u6df1\u5ea6\u9002\u914d&#xff08;\u5206\u652f main-3.3.0-OH&#xff0c;\u6700\u65b0 tag v3.3.0-1.0.0&#xff09;\u3002\u6211\u5728 clone \u4ed3\u5e93\u540e\u8bfb\u53d6\u4e86 ohosArm64Main \u4e0b\u7684 7 \u4e2a\u771f\u5b9e\u6e90\u7801\u6587\u4ef6&#xff0c;\u53d1\u73b0\u5b83\u4e0d\u4ec5\u662f\u7b80\u5355\u7684 target \u58f0\u660e\u2014\u2014\u800c\u662f\u9488\u5bf9\u9e3f\u8499\u5e73\u53f0\u505a\u4e86 DMA \u786c\u4ef6\u52a0\u901f\u89e3\u7801\u5668\u3001\u539f\u751f HEIF \u52a8\u56fe\u89e3\u6790\u3001ServiceLoader \u66ff\u4ee3\u673a\u5236 \u7b49\u6df1\u5ea6\u5b9a\u5236\u3002<\/p>\n<p>\u672c\u6587\u6240\u6709\u6280\u672f\u7ec6\u8282\u5747\u6765\u81ea\u5bf9 CPF-KMP-CMP\/coil \u548c CPF-KMP-CMP\/compose-multiplatform \u4e24\u4e2a\u4ed3\u5e93\u7684\u6e90\u7801\u63a2\u67e5&#xff0c;\u7248\u672c\u53f7\u3001DSL \u914d\u7f6e\u3001linkerOpts\u3001ServiceLoader \u6ce8\u518c\u673a\u5236\u5168\u90e8\u57fa\u4e8e\u771f\u5b9e\u4ee3\u7801\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u5f00\u53d1\u73af\u5883<\/h3>\n<table>\n<tr>\u7ec4\u4ef6\u6307\u5b9a\u7248\u672c\u5907\u6ce8<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">DevEco Studio<\/td>\n<td align=\"left\">26.0.0 Release<\/td>\n<td align=\"left\">HarmonyOS SDK 6.0.0(20) \u65b0\u7248\u547d\u540d<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">HarmonyOS SDK<\/td>\n<td align=\"left\">6.0.0(20)<\/td>\n<td align=\"left\">\u26a0\ufe0f KMP\/CMP \u7528 6.0.0(20)&#xff0c;\u4e0d\u662f 7.0.0(26)<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Kotlin Multiplatform<\/td>\n<td align=\"left\">2.2.21-1.0.0&#xff08;CPF \u5b9a\u5236\u7248&#xff09;<\/td>\n<td align=\"left\">\u6765\u81ea coil-oh \u7684 libs.versions.toml<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">JetBrains Compose<\/td>\n<td align=\"left\">1.9.2-1.0.0&#xff08;CPF \u5b9a\u5236\u7248&#xff09;<\/td>\n<td align=\"left\">org.jetbrains.compose gradle \u63d2\u4ef6<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Coroutines<\/td>\n<td align=\"left\">1.10.2-1.0.0<\/td>\n<td align=\"left\">CPF \u5b9a\u5236\u7248<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Skiko<\/td>\n<td align=\"left\">0.9.22.2-1.0.0<\/td>\n<td align=\"left\">Kotlin\/Native Skia \u7ed1\u5b9a&#xff0c;\u9e3f\u8499\u7aef\u6e32\u67d3\u6838\u5fc3<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Ktor3<\/td>\n<td align=\"left\">3.3.3-1.1.0-04<\/td>\n<td align=\"left\">coil-network-ktor3 \u4f9d\u8d56\u7684\u7f51\u7edc\u6808<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Gradle JDK<\/td>\n<td align=\"left\">JDK 17<\/td>\n<td align=\"left\">DevEco Studio 26 \u7248\u81ea\u5e26<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">OHOS NDK<\/td>\n<td align=\"left\">\u4e0e SDK 6.0.0(20) \u914d\u5957<\/td>\n<td align=\"left\">\u9700\u8bbe\u7f6e OHOS_NDK_HOME \u73af\u5883\u53d8\u91cf<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u9e3f\u8499\u8bbe\u5907<\/td>\n<td align=\"left\">\u771f\u673a ROM 6.1&#043;<\/td>\n<td align=\"left\">ohosArm64 target<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u73af\u5883\u642d\u5efa\u6307\u5f15<\/h4>\n<ul>\n<li>DevEco Studio \u4e0b\u8f7d&#xff1a;\u534e\u4e3a\u4e91\u5f00\u53d1\u8005\u5b98\u7f51<\/li>\n<li>HarmonyOS SDK \u914d\u7f6e&#xff1a;DevEco \u2192 Settings \u2192 SDK Manager \u2192 \u52fe\u9009 6.0.0(20) &#043; Native &#043; NAPI<\/li>\n<li>OHOS_NDK_HOME \u8bbe\u7f6e&#xff1a;Windows \u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u6307\u5411 NDK \u6839\u76ee\u5f55.<\/li>\n<\/ul>\n<p>\u5f00\u53d1\u5b9e\u6d4b\u73af\u5883\u5982\u4e0b&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030112456-6ae47e8856b52.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<hr \/>\n<h3>\u4e09\u3001Coil \u9002\u914d\u72b6\u6001 &amp; \u7248\u672c\u5bf9\u6bd4<\/h3>\n<h4>3.1 CPF-KMP-CMP \u9e3f\u8499\u5b9a\u5236\u7248 vs \u4e0a\u6e38 Maven Central<\/h4>\n<table>\n<tr>\u9879\u76ee\u7248\u672cohosArm64ohosX64\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">CPF-KMP-CMP \u9e3f\u8499\u5b9a\u5236<\/td>\n<td align=\"left\">3.3.0&#xff08;branch main-3.3.0-OH&#xff09;<\/td>\n<td align=\"center\">\u2705<\/td>\n<td align=\"center\">\u26a0\ufe0f compose-multiplatform \u652f\u6301&#xff0c;coil-oh \u6682\u672a\u542f\u7528<\/td>\n<td align=\"left\">\u6df1\u5ea6\u9002\u914d\u9e3f\u8499&#xff0c;\u542b DMA \u89e3\u7801\u5668<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Maven Central \u4e0a\u6e38<\/td>\n<td align=\"left\">3.3.0<\/td>\n<td align=\"center\">\u274c<\/td>\n<td align=\"center\">\u274c<\/td>\n<td align=\"left\">\u901a\u7528\u7248\u672c&#xff0c;\u53ea\u6709 Android\/iOS\/JVM\/Desktop<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#x1f4a1; ohosX64 \u8bf4\u660e&#xff1a;CPF compose-multiplatform \u5df2\u5b8c\u6574\u652f\u6301 ohosX64\u2014\u2014cmp-oh \u4ed3\u5e93\u91cc\u6709 ohosX64Main \u76ee\u5f55&#xff08;ResourceEnvironment\u3001ResourceReader \u7b49\u6e90\u7801&#xff09;\u3002\u4f46 coil-oh \u7684 addAllMultiplatformTargets() \u76ee\u524d\u53ea\u58f0\u660e\u4e86 ohosArm64()&#xff0c;\u6ca1\u6709 ohosX64()\u3002\u5982\u679c\u4f60\u9700\u8981\u6a21\u62df\u5668\u8c03\u8bd5&#xff0c;\u53ef\u5728\u81ea\u5df1\u9879\u76ee\u7684 kotlin {} \u5757\u91cc\u989d\u5916\u58f0\u660e&#xff1a;ohosX64 { binaries.sharedLib { baseName &#061; &#034;coildemo&#034; } }\u3002<\/p>\n<h4>3.2 \u7248\u672c\u53f7\u5168\u666f&#xff08;\u6765\u81ea coil-oh \u7684 gradle\/libs.versions.toml&#xff09;<\/h4>\n<p>\u8fd9\u662f\u76f4\u63a5\u4ece\u4ed3\u5e93\u6e90\u7801\u91cc\u8bfb\u51fa\u6765\u7684\u771f\u5b9e\u7248\u672c\u53f7\u3002\u6ce8\u610f\u7248\u672c\u53f7\u540e\u7f00\u2014\u2014-1.0.0 \u6216 -0.3.0-07 \u8fd9\u79cd\u683c\u5f0f\u4e0d\u662f\u4e0a\u6e38\u539f\u751f\u7248\u672c\u53f7&#xff0c;\u800c\u662f CPF \u793e\u533a\u5728\u4e0a\u6e38\u7248\u672c\u57fa\u7840\u4e0a\u505a\u4e86\u9e3f\u8499\u9002\u914d patch \u540e\u91cd\u65b0\u53d1\u5e03\u7684\u7248\u672c\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u8981\u52a0 patch \u53f7&#xff1f;\u56e0\u4e3a&#xff1a;<\/p>\n<li>Kotlin \u5b98\u65b9\u7684 2.2.21 \u4e0d\u8ba4\u8bc6 ohosArm64 \u8fd9\u4e2a KonanTarget&#xff0c;CPF fork \u540e patch \u4e86 Kotlin\/Native \u7f16\u8bd1\u5668\u4f7f\u5176\u80fd\u8bc6\u522b\u9e3f\u8499 target<\/li>\n<li>Compose \u5b98\u65b9\u7684 1.9.2 \u4e0d\u5305\u542b\u9e3f\u8499\u6e32\u67d3\u540e\u7aef&#xff0c;CPF \u5728 compose-multiplatform \u63d2\u4ef6\u91cc\u52a0\u4e86 compose { ohos { } } DSL \u548c fusion-renderer \u5b9e\u73b0<\/li>\n<li>\u5176\u4ed6\u4f9d\u8d56&#xff08;Coroutines\u3001Okio\u3001AtomicFu&#xff09;\u4e5f\u9700\u8981\u786e\u4fdd\u80fd\u5728 ohosArm64 \u4e0a\u7f16\u8bd1\u901a\u8fc7&#xff0c;\u6240\u4ee5\u7edf\u4e00 patch \u7248\u672c<\/li>\n<p># CPF \u5b9a\u5236\u7248\u672c\u53f7\u5168\u666f \u2014\u2014 \u6ce8\u610f\u6240\u6709\u7248\u672c\u90fd\u5e26 CPF patch \u540e\u7f00<br \/>\nkotlin &#061; &#034;2.2.21-1.0.0&#034;          # Kotlin \u5b98\u65b9 2.2.21 &#043; CPF ohosArm64 target patch<br \/>\njetbrains-compose &#061; &#034;1.9.2-1.0.0&#034;  # Compose \u5b98\u65b9 1.9.2 &#043; CPF fusion-renderer &#043; ohos DSL<br \/>\ncoroutines &#061; &#034;1.10.2-1.0.0&#034;       # Coroutines \u5b98\u65b9 1.10.2 &#043; CPF ohosArm64 \u7f16\u8bd1\u4fee\u6b63<br \/>\nskiko &#061; &#034;0.9.22.2-1.0.0&#034;          # Skiko \u5b98\u65b9 0.9.22.2 &#043; CPF ohosArm64 \u4ea4\u53c9\u7f16\u8bd1\u4ea7\u7269<br \/>\nktor3 &#061; &#034;3.3.3-1.1.0-04&#034;          # Ktor3 \u5b98\u65b9 3.3.3 &#043; CPF ohos \u7f51\u7edc\u5f15\u64ce\u9002\u914d<br \/>\natomicfu &#061; &#034;0.31.0-1.0.0&#034;         # AtomicFu \u5b98\u65b9 0.31.0 &#043; CPF ohos \u539f\u5b50\u64cd\u4f5c\u652f\u6301<br \/>\nokio &#061; &#034;3.16.4-1.0.0&#034;             # Okio \u5b98\u65b9 3.16.4 &#043; CPF ohos \u6587\u4ef6\u7cfb\u7edf\u9002\u914d<br \/>\nkotlinx-serialization &#061; &#034;1.9.1-1.0.0&#034;<br \/>\nAGP &#061; &#034;8.11.2&#034;<\/p>\n<h4>3.3 CPF \u4ed3\u5e93\u771f\u5b9e Maven \u914d\u7f6e&#xff08;\u6765\u81ea build.gradle.kts&#xff09;<\/h4>\n<p>\u8fd9\u662f coil-oh \u6839\u76ee\u5f55\u7684 allprojects \u4ed3\u5e93\u914d\u7f6e\u3002\u6ce8\u610f\u5b83\u7528\u4e86 \u4e09\u4e2a Nexus \u4ed3\u5e93 \u800c\u4e0d\u662f\u4e00\u4e2a&#xff1a;<\/p>\n<ul>\n<li>maven-develop&#xff1a;\u5185\u90e8\u5f00\u53d1\u5feb\u7167\u7248&#xff08;SNAPSHOT&#xff09;&#xff0c;CI \u6d41\u6c34\u7ebf\u81ea\u52a8\u53d1\u5e03<\/li>\n<li>maven-releases&#xff1a;\u6b63\u5f0f\u53d1\u5e03\u7248&#xff0c;\u6bcf\u4e2a tag \u5bf9\u5e94\u4e00\u4e2a\u7248\u672c<\/li>\n<li>maven-public&#xff1a;\u5bf9\u5916\u516c\u5f00\u7248&#xff0c;\u4e5f\u662f maven-releases \u7684\u5b50\u96c6&#xff08;\u516c\u5f00\u53ef\u8bbf\u95ee&#xff09;<\/li>\n<\/ul>\n<p>\u5982\u679c\u4f60\u5728 maven-public \u91cc\u627e\u4e0d\u5230\u67d0\u4e2a artifact&#xff08;\u6bd4\u5982\u8fd8\u6ca1\u6b63\u5f0f\u53d1\u5e03\u7684 SNAPSHOT&#xff09;&#xff0c;\u8bd5\u8bd5 maven-releases \u6216 maven-develop\u3002\u4e09\u4e2a\u90fd\u6392\u5728\u524d\u9762\u662f\u4e3a\u4e86\u786e\u4fdd Gradle \u4f18\u5148\u4ece CPF \u6e90\u62c9\u53d6&#xff0c;\u4e0d\u4f1a\u88ab mavenCentral \u7684\u4e0a\u6e38\u672a\u9002\u914d\u7248\u672c\u62a2\u8d70\u3002<\/p>\n<p><span class=\"token comment\">\/\/ coil-oh \u6839\u76ee\u5f55 build.gradle.kts \u2014\u2014 allprojects \u4ed3\u5e93\u914d\u7f6e<\/span><br \/>\nallprojects <span class=\"token punctuation\">{<\/span><br \/>\n    repositories <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">maven<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/maven.eazytec-cloud.com\/nexus\/repository\/maven-develop\/&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span>   <span class=\"token comment\">\/\/ \u2460 \u5185\u90e8\u5f00\u53d1\u5feb\u7167\u7248<\/span><br \/>\n        <span class=\"token function\">maven<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/maven.eazytec-cloud.com\/nexus\/repository\/maven-releases\/&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ \u2461 \u6b63\u5f0f\u53d1\u5e03\u7248<\/span><br \/>\n        <span class=\"token function\">maven<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/maven.eazytec-cloud.com\/nexus\/repository\/maven-public\/&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span>    <span class=\"token comment\">\/\/ \u2462 \u5bf9\u5916\u516c\u5f00\u7248<\/span><br \/>\n        <span class=\"token function\">google<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>                                                                 <span class=\"token comment\">\/\/ Android SDK \u4ed3\u5e93&#xff08;Coil \u7684 Android \u7aef\u4f9d\u8d56&#xff09;<\/span><br \/>\n        <span class=\"token function\">mavenCentral<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>                                                           <span class=\"token comment\">\/\/ \u901a\u7528 JVM \u4f9d\u8d56<\/span><br \/>\n        <span class=\"token function\">maven<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/maven.pkg.jetbrains.space\/public\/p\/compose\/dev&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span>          <span class=\"token comment\">\/\/ JetBrains Compose dev \u9884\u89c8<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>3.4 \u4f9d\u8d56\u94fe\u5168\u666f&#xff08;\u57fa\u4e8e\u6e90\u7801\u5206\u6790&#xff09;<\/h4>\n<p>\u7406\u89e3\u8fd9\u6761\u4f9d\u8d56\u94fe\u5f88\u91cd\u8981\u2014\u2014\u5b83\u89e3\u91ca\u4e86\u4e3a\u4ec0\u4e48\u914d\u7f6e CPF \u4ed3\u5e93\u662f\u5fc5\u987b\u7684&#xff0c;\u800c\u4e0d\u662f\u53ef\u9009\u7684\u3002\u6574\u4e2a\u94fe\u6761\u4e0a\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u88ab CPF patch \u8fc7&#xff0c;\u4e0a\u6e38 mavenCentral \u91cc\u7684\u7248\u672c\u4e0d\u542b\u9e3f\u8499 target\u3002<\/p>\n<p>coil-compose:3.3.0 (CPF maven-public)<br \/>\n  \u251c\u2500\u2500 coil:3.3.0 \u2192 coil-core:3.3.0<br \/>\n  \u2502     \u251c\u2500\u2500 coroutines-core:1.10.2-1.0.0 (CPF patch)<br \/>\n  \u2502     \u251c\u2500\u2500 okio:3.16.4-1.0.0 (CPF patch)<br \/>\n  \u2502     \u251c\u2500\u2500 compose.ui:1.9.2-1.0.0 (CPF compose-multiplatform&#xff0c;\u542b ohosArm64 \u7f16\u8bd1\u4ea7\u7269)<br \/>\n  \u2502     \u251c\u2500\u2500 nonAndroidMain \u2192 skiko:0.9.22.2-1.0.0 (Skia Kotlin\/Native \u7ed1\u5b9a&#xff0c;CPF \u4ea4\u53c9\u7f16\u8bd1 ohosArm64)<br \/>\n  \u2502     \u2514\u2500\u2500 ohosArm64Main \u2192 OhosNativeDmaDecoder (\u9e3f\u8499 DMA \u786c\u4ef6\u89e3\u7801\u5668&#xff0c;CPF \u72ec\u5bb6)<br \/>\n  \u251c\u2500\u2500 coil-network-ktor3:3.3.0<br \/>\n  \u2502     \u2514\u2500\u2500 ohosArm64Main \u2192 KtorNetworkFetcherServiceLoaderTarget (&#064;EagerInitialization \u6ce8\u518c)<br \/>\n  \u251c\u2500\u2500 coil-gif \u2192 ohosArm64Main \u2192 OhosImageDecoder (\u9e3f\u8499\u539f\u751f C&#043;&#043; HEIF \u52a8\u753b\u89e3\u7801)<br \/>\n  \u2514\u2500\u2500 coil-svg \u2192 ohosArm64Main \u2192 SvgDecoderServiceLoaderTarget (&#064;EagerInitialization \u6ce8\u518c)<\/p>\n<hr \/>\n<h3>\u56db\u3001\u5982\u4f55\u5728\u9e3f\u8499 CMP \u9879\u76ee\u4e2d\u5f15\u5165 Coil<\/h3>\n<h4>4.1 \u9879\u76ee\u7ed3\u6784<\/h4>\n<p>\u9e3f\u8499\u4e0a\u8fd0\u884c Compose Multiplatform \u6709\u4e24\u79cd\u65b9\u5f0f&#xff0c;\u6211\u5206\u522b\u8bf4\u660e\u5b83\u4eec\u7684\u9002\u7528\u573a\u666f\u548c\u6280\u672f\u5dee\u5f02&#xff1a;<\/p>\n<p>\u65b9\u5f0f A&#xff1a;Compose Multiplatform &#043; fusion-renderer&#xff08;\u2705 compose-multiplatform \u9ed8\u8ba4&#xff0c;\u672c\u6587\u8d70\u8fd9\u4e2a&#xff09;<br \/>\n  \u2193 composeApp\/src\/ohosArm64Main\/ \u2014\u2014 \u771f\u6b63\u7684 Compose UI \u6e90\u7801<br \/>\n  \u2193 compose { ohos { fusionRenderer() } } \u2014\u2014 CPF compose-multiplatform \u81ea\u52a8\u914d\u7f6e<br \/>\n  \u2193 \u9ed8\u8ba4\u6e32\u67d3\u540e\u7aef&#xff1a;fusion-renderer&#xff08;\u57fa\u4e8e\u9e3f\u8499\u539f\u751f OpenGL ES &#043; Skiko \u6865\u63a5&#xff09;<br \/>\n  \u2193 UI \u627f\u8f7d\u65b9\u5f0f&#xff1a;Skiko \u539f\u751f\u6e32\u67d3\u5c42&#xff08;compose-multiplatform-core \u7684 ohosArm64 \u4ea4\u53c9\u7f16\u8bd1\u4ea7\u7269&#xff09;<br \/>\n  \u2193 \u2705 Coil \u7684 AsyncImage \u80fd\u76f4\u63a5\u663e\u793a\u5728\u9e3f\u8499\u5c4f\u5e55\u4e0a<\/p>\n<p>\u65b9\u5f0f B&#xff1a;KMP \u903b\u8f91\u5c42 &#043; ArkTS UI \u5c42&#xff08;\u7eaf KMP\/NAPI \u4e92\u64cd\u4f5c&#xff09;<br \/>\n  \u2193 composeApp \u53ea\u662f\u7eaf Kotlin\/Native&#xff0c;\u5bfc\u51fa &#064;CName \u51fd\u6570<br \/>\n  \u2193 HarmonyOS \u5bbf\u4e3b\u5de5\u7a0b\u662f\u7eaf ArkTS&#xff08;\u65e0 Compose UI&#xff09;<br \/>\n  \u2193 \u274c Coil \u5728\u8fd9\u91cc\u53ea\u80fd\u505a\u56fe\u7247\u89e3\u7801\u903b\u8f91&#xff0c;\u4e0d\u80fd\u76f4\u63a5\u6e32\u67d3\u5230\u5c4f\u5e55<\/p>\n<p>\u65b9\u5f0f A \u662f\u771f\u6b63\u7684 CMP \u5b8c\u6574\u5f62\u6001\u2014\u2014\u4e00\u5957 Compose \u4ee3\u7801\u4e09\u7aef\u76f4\u63a5\u8fd0\u884c\u3002\u65b9\u5f0f B \u9002\u5408\u5df2\u6709 ArkTS UI \u7684\u8001\u9879\u76ee\u590d\u7528 KMP \u903b\u8f91\u5c42&#xff0c;\u4f46 Compose UI \u65e0\u6cd5\u76f4\u63a5\u6e32\u67d3\u5230\u5c4f\u5e55\u3002<\/p>\n<p>\u26a0\ufe0f \u9e3f\u8499 Compose UI \u627f\u8f7d\u65b9\u5f0f\u8bf4\u660e&#xff1a;compose-multiplatform-core&#xff08;Skiko \u8fd0\u884c\u65f6&#xff09;\u548c compose-multiplatform&#xff08;Gradle \u63d2\u4ef6&#xff09;\u5df2\u5b8c\u6210 ohosArm64 \u9002\u914d&#xff0c;fusion-renderer \u901a\u8fc7\u9e3f\u8499\u539f\u751f OpenGL ES \u6865\u63a5 Skiko \u6e32\u67d3\u3002\u4f46 ComposeView \u7ea7\u522b\u7684\u9e3f\u8499\u4e92\u64cd\u4f5c\u5c42&#xff08;\u7c7b\u4f3c Android \u7684 androidx.compose.ui.platform.ComposeView&#xff09;\u5728\u5f53\u524d cmp-oh \u4ed3\u5e93\u7684 example \u4e2d\u672a\u627e\u5230\u2014\u2014\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u901a\u5e38\u901a\u8fc7 NAPI \u6865\u63a5 ArkTS \u5bbf\u4e3b &#043; &#064;CName \u5bfc\u51fa Compose \u5165\u53e3\u51fd\u6570\u7684\u65b9\u5f0f\u627f\u8f7d\u3002<\/p>\n<h4>4.2 settings.gradle.kts \u4ed3\u5e93\u914d\u7f6e<\/h4>\n<p>settings.gradle.kts \u662f Gradle \u542f\u52a8\u65f6\u6700\u5148\u8bfb\u53d6\u7684\u914d\u7f6e\u6587\u4ef6&#xff0c;pluginManagement.repositories \u51b3\u5b9a\u4e86 Gradle \u53bb\u54ea\u91cc\u4e0b\u8f7d Gradle \u63d2\u4ef6\u672c\u8eab&#xff08;\u6bd4\u5982 org.jetbrains.compose \u8fd9\u4e2a Gradle \u63d2\u4ef6 jar&#xff09;&#xff0c;\u800c dependencyResolutionManagement.repositories \u51b3\u5b9a\u4e86\u53bb\u54ea\u91cc\u4e0b\u8f7d\u9879\u76ee\u4f9d\u8d56&#xff08;\u6bd4\u5982 coil-compose \u8fd9\u4e2a Maven artifact&#xff09;\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u4e24\u4e2a repositorie block \u90fd\u8981\u628a CPF Nexus \u653e\u6700\u524d\u9762&#xff1f; \u56e0\u4e3a Gradle \u7684\u4f9d\u8d56\u89e3\u6790\u7b56\u7565\u662f&#034;\u627e\u5230\u7b2c\u4e00\u4e2a\u5339\u914d\u5c31\u505c&#034;\u2014\u2014\u5982\u679c mavenCentral \u6392\u5728\u524d\u9762&#xff0c;\u5b83\u4f1a\u5339\u914d\u5230\u4e0a\u6e38\u672a patch \u7684 Compose \u63d2\u4ef6&#xff08;\u4e0d\u542b ohos DSL&#xff09;\u3002CPF \u4ed3\u5e93\u91cc\u7684\u63d2\u4ef6\u548c\u4f9d\u8d56\u90fd\u662f\u5b8c\u6574\u9002\u914d\u8fc7\u9e3f\u8499\u7684&#xff0c;\u5fc5\u987b\u4f18\u5148\u3002<\/p>\n<p><span class=\"token comment\">\/\/ settings.gradle.kts<\/span><br \/>\n<span class=\"token comment\">\/\/ pluginManagement \u8d1f\u8d23\u4e0b\u8f7d Gradle \u63d2\u4ef6\u672c\u8eab<\/span><br \/>\npluginManagement <span class=\"token punctuation\">{<\/span><br \/>\n    repositories <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2460 \u4e09\u4e2a CPF Nexus \u5168\u90e8\u6392\u6700\u524d&#xff01;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u8fd9\u6837 org.jetbrains.compose \u63d2\u4ef6 jar \u4f1a\u4ece CPF \u6e90\u4e0b\u8f7d&#xff08;\u542b ohos DSL&#xff09;&#xff0c;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u800c\u4e0d\u662f\u4ece mavenCentral \u4e0b\u8f7d&#xff08;\u4e0d\u542b ohos \u6269\u5c55&#xff09;<\/span><br \/>\n        <span class=\"token function\">maven<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/maven.eazytec-cloud.com\/nexus\/repository\/maven-develop\/&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token function\">maven<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/maven.eazytec-cloud.com\/nexus\/repository\/maven-releases\/&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token function\">maven<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/maven.eazytec-cloud.com\/nexus\/repository\/maven-public\/&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token function\">gradlePluginPortal<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ \u5b98\u65b9 Gradle \u63d2\u4ef6\u95e8\u6237<\/span><br \/>\n        <span class=\"token function\">google<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>              <span class=\"token comment\">\/\/ Android Gradle Plugin<\/span><br \/>\n        <span class=\"token function\">mavenCentral<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>        <span class=\"token comment\">\/\/ \u901a\u7528\u63d2\u4ef6\u4f9d\u8d56<\/span><br \/>\n        <span class=\"token function\">maven<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/maven.pkg.jetbrains.space\/public\/p\/compose\/dev&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ Compose dev \u9884\u89c8<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ dependencyResolutionManagement \u8d1f\u8d23\u4e0b\u8f7d\u9879\u76ee\u4f9d\u8d56&#xff08;implementation \u91cc\u58f0\u660e\u7684 artifact&#xff09;<\/span><br \/>\ndependencyResolutionManagement <span class=\"token punctuation\">{<\/span><br \/>\n    repositories <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u540c\u6837 CPF \u4e09\u6e90\u6392\u7b2c\u4e00<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u786e\u4fdd coil-compose:3.3.0 \u4ece CPF \u4e0b\u8f7d&#xff08;\u542b ohosArm64 target&#xff09;&#xff0c;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u800c\u4e0d\u662f\u4ece mavenCentral \u4e0b\u8f7d&#xff08;\u53ea\u6709 Android\/iOS\/JVM\/Desktop target&#xff09;<\/span><br \/>\n        <span class=\"token function\">maven<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/maven.eazytec-cloud.com\/nexus\/repository\/maven-develop\/&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token function\">maven<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/maven.eazytec-cloud.com\/nexus\/repository\/maven-releases\/&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token function\">maven<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/maven.eazytec-cloud.com\/nexus\/repository\/maven-public\/&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token function\">mavenCentral<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token function\">google<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>4.3 libs.versions.toml \u7248\u672c\u76ee\u5f55<\/h4>\n<p>\u8fd9\u4e2a\u6587\u4ef6\u7528 Gradle Version Catalog \u7edf\u4e00\u7ba1\u7406\u6240\u6709\u4f9d\u8d56\u7248\u672c\u53f7\u3002\u597d\u5904\u662f&#xff1a;\u9879\u76ee\u91cc\u53ea\u6709\u8fd9\u4e00\u5904\u5199\u7248\u672c\u53f7&#xff0c;kotlin \u7248\u672c\u6539\u4e86\u6574\u4e2a\u9879\u76ee\u81ea\u52a8\u5bf9\u9f50\u3002\u7248\u672c\u53f7\u5168\u90e8\u4ece coil-oh \u4ed3\u5e93\u7684 gradle\/libs.versions.toml \u76f4\u63a5\u8bfb\u53d6&#xff0c;\u786e\u4fdd\u548c CPF \u793e\u533a\u53d1\u5e03\u7684\u9e3f\u8499 artifact \u7248\u672c\u4e25\u683c\u5bf9\u9f50\u3002<\/p>\n<p>\u7279\u522b\u6ce8\u610f plugins \u5757\u91cc\u7684\u4e09\u4e2a Gradle \u63d2\u4ef6 ID&#xff1a;<\/p>\n<ul>\n<li>org.jetbrains.kotlin.multiplatform&#xff1a;KMP \u6838\u5fc3\u63d2\u4ef6&#xff0c;CPF patch \u540e\u80fd\u8bc6\u522b ohosArm64() \u8fd9\u4e2a DSL \u51fd\u6570<\/li>\n<li>org.jetbrains.compose&#xff1a;CPF patch \u540e\u65b0\u589e\u4e86 compose { ohos { } } DSL \u548c fusion-renderer \u9ed8\u8ba4\u914d\u7f6e<\/li>\n<li>org.jetbrains.kotlin.plugin.compose&#xff1a;Compose \u7f16\u8bd1\u5668\u63d2\u4ef6&#xff0c;\u7248\u672c\u5fc5\u987b\u548c Kotlin \u4e25\u683c\u5bf9\u9f50&#xff08;CPF \u7528\u540c\u4e00\u4e2a patch \u53f7&#xff09;<\/li>\n<\/ul>\n<p># gradle\/libs.versions.toml \u2014\u2014 \u4ece coil-oh \u4ed3\u5e93\u76f4\u63a5\u8bfb\u53d6\u7684\u771f\u5b9e\u914d\u7f6e<\/p>\n<p>[versions]<br \/>\n# \u6838\u5fc3\u6846\u67b6\u7248\u672c&#xff08;\u5168\u90e8\u5e26 CPF patch \u540e\u7f00&#xff09;<br \/>\nkotlin &#061; &#034;2.2.21-1.0.0&#034;              # Kotlin \u7f16\u8bd1\u5668&#xff0c;\u542b ohosArm64 target patch<br \/>\njetbrains-compose &#061; &#034;1.9.2-1.0.0&#034;    # Compose Gradle \u63d2\u4ef6&#xff0c;\u542b ohos DSL<br \/>\ncoroutines &#061; &#034;1.10.2-1.0.0&#034;<br \/>\nskiko &#061; &#034;0.9.22.2-1.0.0&#034;<br \/>\nktor3 &#061; &#034;3.3.3-1.1.0-04&#034;<br \/>\nokio &#061; &#034;3.16.4-1.0.0&#034;<br \/>\natomicfu &#061; &#034;0.31.0-1.0.0&#034;<br \/>\nagp &#061; &#034;8.11.2&#034;<br \/>\ncoil &#061; &#034;3.3.0&#034;<\/p>\n<p>[libraries]<br \/>\n# Coil \u6838\u5fc3\u6a21\u5757<br \/>\ncoil-compose &#061; { module &#061; &#034;io.coil-kt.coil3:coil-compose&#034;, version.ref &#061; &#034;coil&#034; }<br \/>\ncoil-network-ktor3 &#061; { module &#061; &#034;io.coil-kt.coil3:coil-network-ktor3&#034;, version.ref &#061; &#034;coil&#034; }<br \/>\ncoil-gif &#061; { module &#061; &#034;io.coil-kt.coil3:coil-gif&#034;, version.ref &#061; &#034;coil&#034; }<br \/>\ncoil-svg &#061; { module &#061; &#034;io.coil-kt.coil3:coil-svg&#034;, version.ref &#061; &#034;coil&#034; }<\/p>\n<p>[plugins]<br \/>\n# Gradle \u63d2\u4ef6 \u2014\u2014 \u6ce8\u610f\u7248\u672c\u53f7\u5f15\u7528\u4e0d\u540c\u7684 version key<br \/>\nkotlin-multiplatform &#061; { id &#061; &#034;org.jetbrains.kotlin.multiplatform&#034;, version.ref &#061; &#034;kotlin&#034; }<br \/>\n# \u2191 \u7248\u672c\u8d70 kotlin &#061; &#034;2.2.21-1.0.0&#034;&#xff08;\u56e0\u4e3a Compose \u7f16\u8bd1\u5668\u63d2\u4ef6\u548c Kotlin \u7248\u672c\u4e25\u683c\u7ed1\u5b9a&#xff09;<br \/>\njetbrains-compose &#061; { id &#061; &#034;org.jetbrains.compose&#034;, version.ref &#061; &#034;jetbrains-compose&#034; }<br \/>\n# \u2191 \u7248\u672c\u8d70 jetbrains-compose &#061; &#034;1.9.2-1.0.0&#034;&#xff08;Compose Gradle \u63d2\u4ef6\u72ec\u7acb\u7248\u672c&#xff09;<br \/>\ncompose-compiler &#061; { id &#061; &#034;org.jetbrains.kotlin.plugin.compose&#034;, version.ref &#061; &#034;kotlin&#034; }<br \/>\nandroid-application &#061; { id &#061; &#034;com.android.application&#034;, version.ref &#061; &#034;agp&#034; }<\/p>\n<h4>4.4 ohosArm64 target &#043; linkerOpts \u8be6\u89e3<\/h4>\n<p>\u8fd9\u662f\u6574\u4e2a\u914d\u7f6e\u4e2d\u6700\u590d\u6742\u7684\u90e8\u5206&#xff0c;\u6211\u9010\u6bb5\u89e3\u6790\u3002<\/p>\n<p>plugins \u5757&#xff1a;\u6ce8\u610f org.jetbrains.compose \u8fd9\u4e2a\u63d2\u4ef6 ID\u2014\u2014\u5f88\u591a\u6587\u7ae0\u4f1a\u5199\u6210 composeMultiplatform&#xff0c;\u4f46 CPF \u4ed3\u5e93\u91cc\u7528\u7684\u662f org.jetbrains.compose\u3002\u8fd9\u4e2a\u63d2\u4ef6\u540d\u5dee\u5f02\u5f88\u5173\u952e\u2014\u2014CPF \u7ed9\u8fd9\u4e2a\u63d2\u4ef6 patch \u4e86\u9e3f\u8499\u6269\u5c55&#xff0c;\u5982\u679c\u7528\u9519\u4e86\u63d2\u4ef6\u540d&#xff0c;compose { ohos { } } DSL \u5c31\u4e0d\u5b58\u5728\u3002<\/p>\n<p>kotlin {} \u5757\u91cc\u7684 ohosArm64&#xff1a;ohosArm64 \u662f\u4e00\u4e2a Kotlin\/Native target&#xff0c;\u7f16\u8bd1\u4ea7\u7269\u662f sharedLib&#xff08;\u52a8\u6001\u94fe\u63a5\u5e93 .so&#xff09;\u800c\u4e0d\u662f executable\u3002\u56e0\u4e3a\u9e3f\u8499\u5e94\u7528\u7684\u4e3b\u7a0b\u5e8f\u662f ArkTS&#xff08;\u901a\u8fc7 NAPI \u6865\u63a5\u8c03\u7528\u8fd9\u4e2a .so&#xff09;&#xff0c;Kotlin \u4ee3\u7801\u53ea\u662f\u88ab\u8c03\u7528\u7684\u5e93\u3002<\/p>\n<p>linkerOpts \u6bcf\u4e00\u884c\u7684\u542b\u4e49&#xff1a;\u8fd9\u4e9b\u94fe\u63a5\u9009\u9879\u662f CPF \u4ece\u9e3f\u8499 NDK \u6e90\u7801\u91cc\u63d0\u53d6\u7684&#xff0c;\u544a\u8bc9 Kotlin\/Native linker \u5728\u751f\u6210 .so \u65f6\u8981\u94fe\u63a5\u54ea\u4e9b\u9e3f\u8499\u7cfb\u7edf\u5e93\u3002<\/p>\n<table>\n<tr>linker flag\u9e3f\u8499\u7cfb\u7edf\u5e93\u4f5c\u7528<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">-lz<\/td>\n<td align=\"left\">\u7cfb\u7edf\u538b\u7f29\u5e93<\/td>\n<td align=\"left\">Kotlin\/Native \u8fd0\u884c\u65f6\u7684\u5f02\u5e38\u5806\u6808\u89e3\u538b\u7f29\u9700\u8981<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">-lhilog_ndk.z<\/td>\n<td align=\"left\">HiLog \u9e3f\u8499\u65e5\u5fd7<\/td>\n<td align=\"left\">Kotlin println\u3001\u5f02\u5e38\u65e5\u5fd7\u901a\u8fc7 HiLog \u8f93\u51fa\u5230\u9e3f\u8499\u65e5\u5fd7\u7cfb\u7edf<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">-licu<\/td>\n<td align=\"left\">Unicode \u56fd\u9645\u5316<\/td>\n<td align=\"left\">\u5b57\u7b26\u4e32\u6bd4\u8f83\u3001\u65e5\u671f\u683c\u5f0f\u5316\u7b49 Unicode \u64cd\u4f5c<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">libunwind.a<\/td>\n<td align=\"left\">LLVM \u6808\u56de\u6eaf<\/td>\n<td align=\"left\">\u5f02\u5e38\u53d1\u751f\u65f6\u751f\u6210\u53ef\u8bfb\u7684\u8c03\u7528\u6808&#xff08;OHOS_NDK_HOME \u91cc\u6709&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>linkerOpts \u91cc ${System.getenv(&#034;OHOS_NDK_HOME&#034;)} \u662f Kotlin \u6a21\u677f\u8bed\u6cd5&#xff0c;\u8fd0\u884c\u65f6\u4f1a\u5c55\u5f00\u6210\u73af\u5883\u53d8\u91cf\u503c\u3002\u5982\u679c\u6ca1\u914d\u8fd9\u4e2a\u73af\u5883\u53d8\u91cf&#xff0c;linkDebugSharedOhosArm64 \u4f1a\u62a5\u627e\u4e0d\u5230 libunwind.a\u3002<\/p>\n<p><span class=\"token comment\">\/\/ composeApp\/build.gradle.kts<\/span><br \/>\n<span class=\"token comment\">\/\/ \u8fd9\u4e2a\u6587\u4ef6\u7684\u5b8c\u6574\u5185\u5bb9\u57fa\u4e8e coil-oh \u7684\u771f\u5b9e\u6a21\u5757\u914d\u7f6e<\/span><\/p>\n<p>plugins <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ Kotlin \u591a\u5e73\u53f0\u6838\u5fc3\u63d2\u4ef6 \u2014\u2014 patch \u540e\u8bc6\u522b ohosArm64() DSL<\/span><br \/>\n    <span class=\"token function\">alias<\/span><span class=\"token punctuation\">(<\/span>libs<span class=\"token punctuation\">.<\/span>plugins<span class=\"token punctuation\">.<\/span>kotlin<span class=\"token punctuation\">.<\/span>multiplatform<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\">\/\/ Android \u5bbf\u4e3b\u58f3&#xff08;\u8ba9 Android Studio \u80fd\u8dd1\u8d77\u6765&#xff09;<\/span><br \/>\n    <span class=\"token function\">alias<\/span><span class=\"token punctuation\">(<\/span>libs<span class=\"token punctuation\">.<\/span>plugins<span class=\"token punctuation\">.<\/span>android<span class=\"token punctuation\">.<\/span>application<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u2705 org.jetbrains.compose \u2014\u2014 patch \u540e\u5305\u542b compose { ohos { } } DSL<\/span><br \/>\n    <span class=\"token function\">alias<\/span><span class=\"token punctuation\">(<\/span>libs<span class=\"token punctuation\">.<\/span>plugins<span class=\"token punctuation\">.<\/span>jetbrains<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\">\/\/ Compose \u7f16\u8bd1\u5668 \u2014\u2014 \u7248\u672c\u548c Kotlin \u4e25\u683c\u5bf9\u9f50<\/span><br \/>\n    <span class=\"token function\">alias<\/span><span class=\"token punctuation\">(<\/span>libs<span class=\"token punctuation\">.<\/span>plugins<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>compiler<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>kotlin <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">jvmToolchain<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">17<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ JDK 17&#xff08;DevEco Studio 26 \u81ea\u5e26&#xff09;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ Android &#043; iOS target \u2014\u2014 \u548c\u9e3f\u8499\u5171\u4eab commonMain \u6e90\u7801<\/span><br \/>\n    <span class=\"token function\">androidTarget<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token function\">iosX64<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token function\">iosArm64<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token function\">iosSimulatorArm64<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u2b50 ohosArm64 target \u2014\u2014 \u9e3f\u8499\u7684\u6838\u5fc3\u7f16\u8bd1\u76ee\u6807<\/span><br \/>\n    ohosArm64 <span class=\"token punctuation\">{<\/span><br \/>\n        binaries <span class=\"token punctuation\">{<\/span><br \/>\n            all <span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token comment\">\/\/ \u9e3f\u8499\u539f\u751f linkerOpts \u2014\u2014 \u6bcf\u4e00\u884c\u90fd\u6709\u660e\u786e\u4f5c\u7528<\/span><br \/>\n                <span class=\"token comment\">\/\/ \u8fd9\u4e9b\u914d\u7f6e\u6765\u81ea coil-oh\/buildSrc\/src\/main\/kotlin\/coil3\/multiplatform.kt<\/span><br \/>\n                <span class=\"token function\">linkerOpts<\/span><span class=\"token punctuation\">(<\/span><br \/>\n                    <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;-lz&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span>                                                   <span class=\"token comment\">\/\/ \u9e3f\u8499\u7cfb\u7edf\u538b\u7f29\u5e93&#xff08;\u5f02\u5e38\u5806\u6808\u89e3\u538b&#xff09;<\/span><br \/>\n                    <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;-lhilog_ndk.z&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span>                                         <span class=\"token comment\">\/\/ HiLog \u65e5\u5fd7\u7cfb\u7edf&#xff08;println \u8f93\u51fa&#xff09;<\/span><br \/>\n                    <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;-licu&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span>                                                 <span class=\"token comment\">\/\/ Unicode \u56fd\u9645\u5316&#xff08;\u5b57\u7b26\u4e32\u64cd\u4f5c&#xff09;<\/span><br \/>\n                    <span class=\"token comment\">\/\/ libunwind.a \u662f LLVM \u7684\u9759\u6001\u6808\u56de\u6eaf\u5e93<\/span><br \/>\n                    <span class=\"token comment\">\/\/ \u8def\u5f84\u786c\u7f16\u7801\u4f9d\u8d56 OHOS_NDK_HOME \u73af\u5883\u53d8\u91cf<\/span><br \/>\n                    <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<\/span><span class=\"token expression\">System<span class=\"token punctuation\">.<\/span><span class=\"token function\">getenv<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;OHOS_NDK_HOME&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/span><span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token string\">\/native\/llvm\/lib\/aarch64-linux-ohos\/libunwind.a&#034;<\/span><\/span><br \/>\n                <span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u7f16\u8bd1\u4ea7\u7269\u7c7b\u578b&#xff1a;sharedLib&#xff08;\u52a8\u6001\u94fe\u63a5\u5e93 .so&#xff09;<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u9e3f\u8499\u5e94\u7528\u662f ArkTS \u4e3b\u7a0b\u5e8f &#043; NAPI \u8c03\u7528\u8fd9\u4e2a .so<\/span><br \/>\n            sharedLib <span class=\"token punctuation\">{<\/span><br \/>\n                baseName <span class=\"token operator\">&#061;<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;coildemo&#034;<\/span><\/span>  <span class=\"token comment\">\/\/ \u6700\u7ec8\u4ea7\u7269&#xff1a;libcoildemo.so<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    sourceSets <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">val<\/span> commonMain <span class=\"token keyword\">by<\/span> getting <span class=\"token punctuation\">{<\/span><br \/>\n            dependencies <span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token comment\">\/\/ Coil \u6838\u5fc3\u6a21\u5757 \u2014\u2014 commonMain API \u4e0e Android\/iOS\/\u9e3f\u8499 100% \u4e00\u81f4<\/span><br \/>\n                <span class=\"token function\">implementation<\/span><span class=\"token punctuation\">(<\/span>libs<span class=\"token punctuation\">.<\/span>coil<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">)<\/span>           <span class=\"token comment\">\/\/ AsyncImage \/ rememberAsyncImagePainter<\/span><br \/>\n                <span class=\"token function\">implementation<\/span><span class=\"token punctuation\">(<\/span>libs<span class=\"token punctuation\">.<\/span>coil<span class=\"token punctuation\">.<\/span>network<span class=\"token punctuation\">.<\/span>ktor3<span class=\"token punctuation\">)<\/span>     <span class=\"token comment\">\/\/ Ktor3 \u7f51\u7edc\u5f15\u64ce&#xff08;\u9e3f\u8499\u7aef &#064;EagerInitialization \u81ea\u52a8\u6ce8\u518c&#xff09;<\/span><br \/>\n                <span class=\"token comment\">\/\/ \u53ef\u9009\u6a21\u5757 \u2014\u2014 \u6309\u9700\u6dfb\u52a0<\/span><br \/>\n                <span class=\"token function\">implementation<\/span><span class=\"token punctuation\">(<\/span>libs<span class=\"token punctuation\">.<\/span>coil<span class=\"token punctuation\">.<\/span>gif<span class=\"token punctuation\">)<\/span>               <span class=\"token comment\">\/\/ GIF \/ HEIF \u52a8\u753b\u652f\u6301&#xff08;\u9e3f\u8499\u7aef\u6709 actual AsyncImage&#xff09;<\/span><br \/>\n                <span class=\"token function\">implementation<\/span><span class=\"token punctuation\">(<\/span>libs<span class=\"token punctuation\">.<\/span>coil<span class=\"token punctuation\">.<\/span>svg<span class=\"token punctuation\">)<\/span>               <span class=\"token comment\">\/\/ SVG \u89e3\u7801<\/span><\/p>\n<p>                <span class=\"token comment\">\/\/ Compose Multiplatform UI \u6846\u67b6\u6838\u5fc3<\/span><br \/>\n                <span class=\"token function\">implementation<\/span><span class=\"token punctuation\">(<\/span>compose<span class=\"token punctuation\">.<\/span>runtime<span class=\"token punctuation\">)<\/span>              <span class=\"token comment\">\/\/ Compose \u8fd0\u884c\u65f6&#xff08;\u91cd\u7ec4\u3001\u5feb\u7167&#xff09;<\/span><br \/>\n                <span class=\"token function\">implementation<\/span><span class=\"token punctuation\">(<\/span>compose<span class=\"token punctuation\">.<\/span>foundation<span class=\"token punctuation\">)<\/span>           <span class=\"token comment\">\/\/ \u57fa\u7840\u7ec4\u4ef6&#xff08;LazyColumn\u3001Image \u7b49&#xff09;<\/span><br \/>\n                <span class=\"token function\">implementation<\/span><span class=\"token punctuation\">(<\/span>compose<span class=\"token punctuation\">.<\/span>material<span class=\"token punctuation\">)<\/span>              <span class=\"token comment\">\/\/ Material Design 2<\/span><br \/>\n                <span class=\"token function\">implementation<\/span><span class=\"token punctuation\">(<\/span>compose<span class=\"token punctuation\">.<\/span>material3<span class=\"token punctuation\">)<\/span>             <span class=\"token comment\">\/\/ Material Design 3<\/span><br \/>\n                <span class=\"token function\">implementation<\/span><span class=\"token punctuation\">(<\/span>compose<span class=\"token punctuation\">.<\/span>ui<span class=\"token punctuation\">)<\/span>                   <span class=\"token comment\">\/\/ UI \u539f\u8bed&#xff08;Modifier\u3001Alignment&#xff09;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ nonAndroidMain \u662f CPF \u81ea\u5b9a\u4e49\u7684 sourceSet<\/span><br \/>\n        <span class=\"token comment\">\/\/ ohosArm64 \u4f1a\u7ee7\u627f\u5b83&#xff08;\u89c1 hierarchy template \u8bbe\u8ba1&#xff09;<\/span><br \/>\n        <span class=\"token keyword\">val<\/span> nonAndroidMain <span class=\"token keyword\">by<\/span> getting <span class=\"token punctuation\">{<\/span><br \/>\n            dependencies <span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token comment\">\/\/ Skiko &#061; Skia \u7684 Kotlin\/Native \u7ed1\u5b9a<\/span><br \/>\n                <span class=\"token comment\">\/\/ ohosArm64 \u7f16\u8bd1\u65f6\u4f1a\u81ea\u52a8\u7528 skiko-ohosarm64 \u8fd9\u4e2a variant<\/span><br \/>\n                <span class=\"token comment\">\/\/ compose-multiplatform \u63d2\u4ef6\u4f1a\u5728 afterEvaluate \u9636\u6bb5\u81ea\u52a8\u8986\u76d6 Skiko \u7248\u672c<\/span><br \/>\n                <span class=\"token function\">implementation<\/span><span class=\"token punctuation\">(<\/span>libs<span class=\"token punctuation\">.<\/span>skiko<span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u2b50 compose { ohos { } } DSL \u2014\u2014 CPF compose-multiplatform patch \u540e\u65b0\u589e\u7684\u9e3f\u8499\u914d\u7f6e\u5757<\/span><br \/>\n<span class=\"token comment\">\/\/ \u4f18\u5148\u7ea7&#xff08;compose-multiplatform ComposePlugin.kt \u6e90\u7801\u91cc\u660e\u786e\u5199\u4e86&#xff09;&#xff1a;<\/span><br \/>\n<span class=\"token comment\">\/\/ 1. \u547d\u4ee4\u884c -PrendererBackend&#061;skia \u6216 -PrendererBackend&#061;fusion-renderer<\/span><br \/>\n<span class=\"token comment\">\/\/ 2. \u8fd9\u91cc\u7684 compose { ohos { &#8230; } } DSL \u914d\u7f6e<\/span><br \/>\n<span class=\"token comment\">\/\/ 3. \u9ed8\u8ba4 fusion-renderer&#xff08;compose-plugin \u5185\u7f6e\u7248\u672c\u81ea\u52a8\u751f\u6548&#xff09;<\/span><br \/>\ncompose <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ fusion-renderer \u662f\u9e3f\u8499\u63a8\u8350\u7684\u6e32\u67d3\u540e\u7aef<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5b83\u901a\u8fc7\u9e3f\u8499\u539f\u751f OpenGL ES API&#xff08;EGL&#xff09;\u6865\u63a5 Skiko Skia \u6e32\u67d3<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u6bd4\u7eaf Skia \u8f6f\u4ef6\u6e32\u67d3\u6027\u80fd\u66f4\u597d&#xff0c;\u6709\u9e3f\u8499\u7cfb\u7edf\u7ea7 GPU \u4f18\u5316<\/span><br \/>\n    ohos <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">fusionRenderer<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ \u5199\u4e0d\u5199\u90fd\u884c&#xff0c;\u9ed8\u8ba4\u5c31\u662f\u5b83<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u5982\u679c\u60f3\u5f3a\u5236\u7528\u7eaf Skia \u6e32\u67d3&#xff08;\u6bd4\u5982\u8c03\u8bd5 fusion-renderer \u7684\u517c\u5bb9\u6027\u95ee\u9898&#xff09;&#xff1a;<\/span><br \/>\n    <span class=\"token comment\">\/\/ ohos { skiko(&#034;0.9.22.2-1.0.0&#034;) }<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ enableStrongSkippingMode \u662f Compose \u7f16\u8bd1\u5668\u7684\u91cd\u7ec4\u4f18\u5316\u5f00\u5173<\/span><br \/>\n<span class=\"token comment\">\/\/ \u5f00\u542f\u540e Compose \u4f1a\u66f4\u7cbe\u786e\u5730\u5224\u65ad&#034;\u54ea\u4e9b Composable \u53ef\u4ee5\u8df3\u8fc7\u91cd\u7ec4&#034;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u5bf9\u4e8e AsyncImage \u8fd9\u79cd\u91cd IO \u7684\u7ec4\u4ef6\u7279\u522b\u91cd\u8981\u2014\u2014\u51cf\u5c11\u65e0\u610f\u4e49\u7684\u91cd\u590d\u4e0b\u8f7d<\/span><br \/>\ncomposeCompiler <span class=\"token punctuation\">{<\/span><br \/>\n    enableStrongSkippingMode <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">true<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>4.5 \u9e3f\u8499\u7279\u6709\u673a\u5236\u4e00&#xff1a;OhosNativeDmaDecoder \u6df1\u5ea6\u89e3\u6790<\/h4>\n<p>\u8fd9\u662f CPF-KMP-CMP \u4e3a\u9e3f\u8499\u505a\u7684\u72ec\u5bb6\u786c\u4ef6\u52a0\u901f\u4f18\u5316\u3002\u6e90\u7801\u5728 coil-core\/src\/ohosArm64Main\/kotlin\/coil3\/decode\/OhosNativeDmaDecoder.kt&#xff08;\u7ea6 150 \u884c&#xff09;\u3002<\/p>\n<p>\u8981\u7406\u89e3\u5b83\u7684\u4ef7\u503c&#xff0c;\u5148\u770b\u5e38\u89c4\u56fe\u7247\u89e3\u7801\u6d41\u7a0b&#xff08;Android\/iOS\/Desktop \u901a\u7528&#xff09;&#xff1a;<\/p>\n<p>\u7f51\u7edc\u4e0b\u8f7d\u56fe\u7247\u5b57\u8282 \u2192 \u5b57\u8282\u5b58\u5165\u5185\u5b58 Buffer \u2192 CPU \u89e3\u7801\u4e3a Skia Image \u2192 \u4e0a\u4f20 GPU \u663e\u5b58<br \/>\n                    \u2191 \u7b2c2\u6b65\u548c\u7b2c3\u6b65\u4e4b\u95f4\u6709 CPU\u2192GPU \u7684\u5185\u5b58\u62f7\u8d1d\u5f00\u9500<\/p>\n<p>\u9e3f\u8499\u7684 DMA&#xff08;Direct Memory Access&#xff09;\u673a\u5236\u53ef\u4ee5\u8df3\u8fc7 CPU \u76f4\u63a5\u4ece\u5185\u5b58\u62f7\u5230 GPU&#xff1a;<\/p>\n<p>\u7f51\u7edc\u4e0b\u8f7d\u56fe\u7247\u5b57\u8282 \u2192 DMA \u5f15\u64ce\u76f4\u63a5\u5199 GPU \u663e\u5b58 \u2192 \u89e3\u7801\u5728 GPU \u7aef\u5b8c\u6210<br \/>\n                    \u2191 \u7701\u6389\u4e86\u4e00\u6b21 CPU \u5185\u5b58\u62f7\u8d1d &#043; \u4e00\u6b21\u4e0a\u4f20<\/p>\n<p>\u4f46 DMA \u89e3\u7801\u5668\u6709\u4e09\u4e2a\u9650\u5236&#xff1a;\u2460 \u53ea\u652f\u6301 JPEG\/PNG\/WebP \u4e09\u79cd\u683c\u5f0f&#xff08;\u6e90\u7801\u91cc SUPPORTED_MIME_TYPES \u5199\u6b7b\u4e86&#xff09;&#xff1b;\u2461 \u9700\u8981\u9e3f\u8499\u8f83\u65b0\u7684 DMA API&#xff1b;\u2462 \u4e0d\u662f\u6240\u6709\u8bbe\u5907\u90fd\u7a33\u5b9a\u652f\u6301\u3002\u6240\u4ee5 CPF \u628a\u5b83\u8bbe\u8ba1\u6210\u53ef\u9009\u7684\u589e\u5f3a\u89e3\u7801\u5668&#xff0c;\u9ed8\u8ba4\u4e0d\u542f\u7528\u3002<\/p>\n<p><span class=\"token comment\">\/\/ coil-core\/src\/ohosArm64Main\/kotlin\/coil3\/decode\/OhosNativeDmaDecoder.kt<\/span><br \/>\n<span class=\"token comment\">\/\/ \u2014\u2014 \u4ece\u4ed3\u5e93\u76f4\u63a5\u8bfb\u53d6\u7684\u771f\u5b9e\u6e90\u7801&#xff0c;\u6211\u52a0\u4e86\u4e2d\u6587\u884c\u5185\u6ce8\u91ca<\/span><\/p>\n<p><span class=\"token keyword\">internal<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token function\">OhosNativeDmaDecoder<\/span><span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">val<\/span> result<span class=\"token operator\">:<\/span> SourceFetchResult<span class=\"token punctuation\">,<\/span>  <span class=\"token comment\">\/\/ Coil \u901a\u7528\u63a5\u53e3&#xff1a;\u5305\u542b\u5df2\u4e0b\u8f7d\u7684\u56fe\u7247\u5b57\u8282\u6216\u6587\u4ef6<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">val<\/span> options<span class=\"token operator\">:<\/span> Options<span class=\"token punctuation\">,<\/span>           <span class=\"token comment\">\/\/ \u89e3\u7801\u53c2\u6570&#xff1a;\u76ee\u6807\u5c3a\u5bf8\u3001\u7f29\u653e\u65b9\u5f0f\u7b49<\/span><br \/>\n<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">:<\/span> Decoder <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token keyword\">override<\/span> <span class=\"token keyword\">suspend<\/span> <span class=\"token keyword\">fun<\/span> <span class=\"token function\">decode<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">:<\/span> DecodeResult<span class=\"token operator\">?<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2460 \u4ece options \u91cc\u53d6 Coil \u4f20\u8fc7\u6765\u7684\u89e3\u7801\u4e0a\u4e0b\u6587<\/span><br \/>\n        <span class=\"token keyword\">val<\/span> targetWidth <span class=\"token operator\">&#061;<\/span> options<span class=\"token punctuation\">.<\/span><span class=\"token function\">targetWidthOrNull<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">val<\/span> targetHeight <span class=\"token operator\">&#061;<\/span> options<span class=\"token punctuation\">.<\/span><span class=\"token function\">targetHeightOrNull<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">val<\/span> decodeContext <span class=\"token operator\">&#061;<\/span> options<span class=\"token punctuation\">.<\/span><span class=\"token function\">getExtra<\/span><span class=\"token punctuation\">(<\/span>OhosImageDecodeContextKey<span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u2461 \u4e24\u6761\u8def\u5f84&#xff1a;\u6587\u4ef6\u4f18\u5148 vs \u5b57\u8282\u4f18\u5148<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5982\u679c Coil \u628a\u56fe\u7247\u5b58\u6210\u4e86\u4e34\u65f6\u6587\u4ef6&#xff0c;\u8d70\u6587\u4ef6\u8def\u5f84&#xff08;\u66f4\u9ad8\u6548&#xff0c;DMA \u80fd\u76f4\u63a5\u8bfb\u6587\u4ef6\u53e5\u67c4&#xff09;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5426\u5219\u4ece\u5185\u5b58\u91cc peek \u51fa\u5168\u90e8\u5b57\u8282\u518d\u89e3\u7801<\/span><br \/>\n        <span class=\"token keyword\">val<\/span> file <span class=\"token operator\">&#061;<\/span> result<span class=\"token punctuation\">.<\/span>source<span class=\"token punctuation\">.<\/span><span class=\"token function\">fileOrNull<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">val<\/span> bitmap <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>file <span class=\"token operator\">!&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u2b50 \u6587\u4ef6\u8def\u5f84&#xff1a;\u8c03\u7528 compose.ui \u63d0\u4f9b\u7684\u9e3f\u8499 DMA API<\/span><br \/>\n            <span class=\"token function\">loadImageBitmapFromFileWithNativeDma<\/span><span class=\"token punctuation\">(<\/span><br \/>\n                filePath <span class=\"token operator\">&#061;<\/span> file<span class=\"token punctuation\">.<\/span><span class=\"token function\">toString<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                decodeContext <span class=\"token operator\">&#061;<\/span> decodeContext<span class=\"token punctuation\">,<\/span><br \/>\n                targetWidthPx <span class=\"token operator\">&#061;<\/span> targetWidth<span class=\"token punctuation\">,<\/span><br \/>\n                targetHeightPx <span class=\"token operator\">&#061;<\/span> targetHeight<span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u2b50 \u5b57\u8282\u8def\u5f84&#xff1a;\u7528 okio peek \u51fa\u5168\u90e8\u5b57\u8282<\/span><br \/>\n            <span class=\"token keyword\">val<\/span> bytes <span class=\"token operator\">&#061;<\/span> result<span class=\"token punctuation\">.<\/span>source<span class=\"token punctuation\">.<\/span><span class=\"token function\">source<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">peek<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">use<\/span> <span class=\"token punctuation\">{<\/span> it<span class=\"token punctuation\">.<\/span><span class=\"token function\">readByteArray<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n            <span class=\"token function\">loadImageBitmapWithNativeDma<\/span><span class=\"token punctuation\">(<\/span>bytes <span class=\"token operator\">&#061;<\/span> bytes<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">..<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span> <span class=\"token operator\">?:<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">null<\/span>  <span class=\"token comment\">\/\/ DMA \u89e3\u7801\u5931\u8d25 \u2192 \u8fd4\u56de null \u89e6\u53d1 fallback<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u2462 \u628a Compose ImageBitmap \u5c01\u88c5\u6210 Coil \u81ea\u5df1\u7684 Image \u63a5\u53e3<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token function\">DecodeResult<\/span><span class=\"token punctuation\">(<\/span><br \/>\n            image <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">OhosComposeImage<\/span><span class=\"token punctuation\">(<\/span>bitmap<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            isSampled <span class=\"token operator\">&#061;<\/span> targetWidth <span class=\"token operator\">!&#061;<\/span> <span class=\"token keyword\">null<\/span> <span class=\"token operator\">&amp;&amp;<\/span> targetHeight <span class=\"token operator\">!&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">,<\/span>  <span class=\"token comment\">\/\/ \u662f\u5426\u505a\u4e86\u91c7\u6837\u964d\u5206\u8fa8\u7387<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/**<br \/>\n     * Factory \u662f Coil Decoder \u4f53\u7cfb\u7684\u6ce8\u518c\u5165\u53e3\u3002<br \/>\n     * Coil \u4f1a\u904d\u5386\u6240\u6709\u6ce8\u518c\u7684 Factory&#xff0c;\u4f9d\u6b21\u8c03\u7528 create()&#xff0c;<br \/>\n     * \u7b2c\u4e00\u4e2a\u8fd4\u56de\u975e null \u7684 Decoder \u5c31\u7528\u6765\u89e3\u7801\u3002<br \/>\n     *\/<\/span><br \/>\n    <span class=\"token keyword\">internal<\/span> <span class=\"token keyword\">class<\/span> Factory <span class=\"token operator\">:<\/span> Decoder<span class=\"token punctuation\">.<\/span><span class=\"token function\">Factory<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">override<\/span> <span class=\"token keyword\">fun<\/span> <span class=\"token function\">create<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">..<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">:<\/span> Decoder<span class=\"token operator\">?<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u2b50\u2b50\u2b50 \u5f00\u5173&#xff1a;\u9ed8\u8ba4 false&#xff0c;\u9700\u8981\u5e94\u7528\u4e3b\u52a8\u8bbe\u6210 true \u624d\u751f\u6548<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u8fd9\u662f Coil \u793e\u533a\u7684\u4fdd\u5b88\u7b56\u7565\u2014\u2014\u65b0\u786c\u4ef6\u52a0\u901f\u5148\u8ba9\u5f00\u53d1\u8005\u81ea\u5df1\u51b3\u5b9a\u8981\u4e0d\u8981\u7528<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span>OhosImageLoadConfig<span class=\"token punctuation\">.<\/span>useNativeDmaDecodeWhenAvailable<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">null<\/span><\/p>\n<p>            <span class=\"token comment\">\/\/ \u2b50 \u683c\u5f0f\u767d\u540d\u5355&#xff1a;\u53ea\u652f\u6301 JPEG\/PNG\/WebP<\/span><br \/>\n            <span class=\"token comment\">\/\/ HEIF\u3001BMP \u7b49\u4e0d\u8d70 DMA&#xff0c;\u5b83\u4eec\u7684\u89e3\u7801\u8def\u5f84\u8fd8\u6ca1\u9002\u914d<\/span><br \/>\n            <span class=\"token keyword\">val<\/span> SUPPORTED_MIME_TYPES <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">setOf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;image\/jpeg&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;image\/png&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;image\/webp&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">val<\/span> mimeType <span class=\"token operator\">&#061;<\/span> result<span class=\"token punctuation\">.<\/span>mimeType<br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>mimeType <span class=\"token operator\">!&#061;<\/span> <span class=\"token keyword\">null<\/span> <span class=\"token operator\">&amp;&amp;<\/span> mimeType <span class=\"token operator\">!<\/span><span class=\"token keyword\">in<\/span> SUPPORTED_MIME_TYPES<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">null<\/span><\/p>\n<p>            <span class=\"token comment\">\/\/ \u901a\u8fc7\u6240\u6709\u68c0\u67e5 \u2192 \u8fd4\u56de DMA \u89e3\u7801\u5668\u5b9e\u4f8b<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token function\">OhosNativeDmaDecoder<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">,<\/span> options<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u5982\u4f55\u5f00\u542f DMA \u52a0\u901f&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u5728\u9e3f\u8499\u5e94\u7528\u5165\u53e3&#xff08;Ability.onCreate \u6216 Application.onCreate&#xff09;\u91cc\u8bbe\u7f6e<\/span><br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>ui<span class=\"token punctuation\">.<\/span>res<span class=\"token punctuation\">.<\/span>OhosImageLoadConfig<\/p>\n<p>OhosImageLoadConfig<span class=\"token punctuation\">.<\/span>useNativeDmaDecodeWhenAvailable <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">true<\/span><br \/>\n<span class=\"token comment\">\/\/ \u4e4b\u540e\u7684 AsyncImage \u52a0\u8f7d JPEG\/PNG\/WebP \u65f6&#xff1a;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u2460 Factory \u68c0\u67e5\u5f00\u5173 \u2192 \u901a\u8fc7<\/span><br \/>\n<span class=\"token comment\">\/\/ \u2461 Factory \u68c0\u67e5 MIME \u7c7b\u578b \u2192 \u901a\u8fc7<\/span><br \/>\n<span class=\"token comment\">\/\/ \u2462 \u8fd4\u56de OhosNativeDmaDecoder \u2192 \u8d70 DMA \u8def\u5f84<\/span><br \/>\n<span class=\"token comment\">\/\/ \u2463 \u5982\u679c DMA \u89e3\u7801\u5931\u8d25&#xff08;\u8bbe\u5907\u4e0d\u652f\u6301\u3001\u6587\u4ef6\u635f\u574f\u3001API \u8fd4\u56de\u7a7a&#xff09;\u2192 Factory \u81ea\u52a8\u8fd4\u56de null \u2192 Coil \u8d70\u4e0b\u4e00\u4e2a\u89e3\u7801\u5668&#xff08;SkiaImageDecoder&#xff09;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u2464 \u4e0d\u4f1a\u5d29\u6e83\u3001\u4e0d\u4f1a\u5361\u4f4f&#xff0c;\u5b8c\u5168\u9759\u9ed8 fallback<\/span><\/p>\n<h4>4.6 \u9e3f\u8499\u7279\u6709\u673a\u5236\u4e8c&#xff1a;ServiceLoader \u2192 &#064;EagerInitialization<\/h4>\n<p>\u8fd9\u662f Kotlin\/Native \u9e3f\u8499\u7aef\u7684\u4e00\u4e2a\u6865\u63a5\u95ee\u9898\u3002<\/p>\n<p>Java \u7684 ServiceLoader \u673a\u5236\u662f\u4ec0\u4e48&#xff1f;\u5b83\u662f\u4e00\u79cd&#034;\u6a21\u5757\u81ea\u52a8\u6ce8\u518c&#034;\u65b9\u5f0f\u2014\u2014\u4f60\u5199\u4e00\u4e2a META-INF\/services\/com.example.MyInterface \u6587\u4ef6&#xff0c;\u91cc\u9762\u5217\u51fa\u5b9e\u73b0\u7c7b\u7684\u5168\u9650\u5b9a\u540d&#xff0c;JVM \u542f\u52a8\u65f6\u81ea\u52a8\u626b classpath \u52a0\u8f7d\u5b9e\u73b0\u7c7b\u3002Android \u4e0a\u7684 Ktor \u7f51\u7edc\u5f15\u64ce\u3001Coil \u7684\u89e3\u7801\u5668\u90fd\u662f\u901a\u8fc7\u8fd9\u4e2a\u673a\u5236\u81ea\u52a8\u6ce8\u518c\u7684\u3002<\/p>\n<p>\u4f46 Kotlin\/Native \u6ca1\u6709 classpath \u6982\u5ff5\u2014\u2014\u7f16\u8bd1\u4ea7\u7269\u662f\u5355\u4e2a\u4e8c\u8fdb\u5236&#xff08;.so \u6216 .kexe&#xff09;&#xff0c;\u6ca1\u6709 META-INF \u76ee\u5f55&#xff0c;\u4e5f\u6ca1\u6709 classpath \u626b\u63cf\u3002\u6240\u4ee5 Java ServiceLoader \u5728\u9e3f\u8499\u7aef\u5b8c\u5168\u4e0d\u53ef\u7528\u3002<\/p>\n<p>CPF \u793e\u533a\u7528 Kotlin\/Native \u7684 &#064;EagerInitialization \u6ce8\u89e3\u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898\u3002\u8fd9\u662f Kotlin\/Native 1.7.20 \u5f15\u5165\u7684\u7279\u6027\u2014\u2014\u88ab &#064;EagerInitialization \u6807\u8bb0\u7684\u9876\u5c42\u5c5e\u6027\u4f1a\u5728\u7a0b\u5e8f\u542f\u52a8\u65f6&#xff08;Kotlin\/Native \u8fd0\u884c\u65f6\u521d\u59cb\u5316\u9636\u6bb5&#xff09;\u81ea\u52a8\u6267\u884c\u5176\u521d\u59cb\u5316\u4ee3\u7801\u3002\u6548\u679c\u7b49\u4ef7\u4e8e Java \u7684 static block \u5728\u7c7b\u52a0\u8f7d\u65f6\u6267\u884c\u3002<\/p>\n<p><span class=\"token comment\">\/\/ coil-network-ktor3\/src\/ohosArm64Main\/&#8230;\/KtorNetworkFetcherServiceLoaderTarget.ohosArm64.kt<\/span><br \/>\n<span class=\"token comment\">\/\/ \u2014\u2014 \u4ece\u4ed3\u5e93\u76f4\u63a5\u8bfb\u53d6\u7684\u771f\u5b9e\u6e90\u7801<\/span><\/p>\n<p><span class=\"token annotation builtin\">&#064;Suppress<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;DEPRECATION&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token annotation builtin\">&#064;OptIn<\/span><span class=\"token punctuation\">(<\/span>ExperimentalStdlibApi<span class=\"token operator\">::<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token annotation builtin\">&#064;EagerInitialization<\/span>   <span class=\"token comment\">\/\/ \u2b50 Kotlin\/Native \u542f\u52a8\u65f6\u81ea\u52a8\u6267\u884c\u8fd9\u4e2a\u5c5e\u6027\u7684\u521d\u59cb\u5316\u5757<\/span><br \/>\n<span class=\"token annotation builtin\">&#064;InternalCoilApi<\/span><br \/>\n<span class=\"token annotation builtin\">&#064;Deprecated<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span> level <span class=\"token operator\">&#061;<\/span> DeprecationLevel<span class=\"token punctuation\">.<\/span>HIDDEN<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">val<\/span> initHook<span class=\"token operator\">:<\/span> Any <span class=\"token operator\">&#061;<\/span> ServiceLoaderComponentRegistry<span class=\"token punctuation\">.<\/span><span class=\"token function\">register<\/span><span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token function\">KtorNetworkFetcherServiceLoaderTarget<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u8fd9\u884c\u4ee3\u7801\u505a\u4e86\u4ec0\u4e48&#xff1f;<\/span><br \/>\n<span class=\"token comment\">\/\/ KtorNetworkFetcherServiceLoaderTarget \u5b9e\u73b0\u4e86 Coil \u7684 NetworkFetcher \u63a5\u53e3<\/span><br \/>\n<span class=\"token comment\">\/\/ register() \u628a\u5b83\u6ce8\u518c\u5230 Coil \u5185\u90e8\u7684\u5168\u5c40 ComponentRegistry<\/span><br \/>\n<span class=\"token comment\">\/\/ \u4e4b\u540e AsyncImage \u9700\u8981\u7f51\u7edc\u52a0\u8f7d\u65f6&#xff0c;\u76f4\u63a5\u4ece Registry \u91cc\u53d6\u5230 Ktor3 \u5b9e\u73b0<\/span><br \/>\n<span class=\"token comment\">\/\/ \u6574\u4e2a\u8fc7\u7a0b\u5bf9\u7528\u6237\u5b8c\u5168\u900f\u660e\u2014\u2014\u4e0d\u9700\u8981\u624b\u52a8 configure ImageLoader<\/span><\/p>\n<p>\u540c\u6837\u7684\u6a21\u5f0f\u7528\u5728 coil-svg\u3001coil-network-ktor2 \u7b49\u6a21\u5757\u3002\u4f60\u53ef\u4ee5\u5728\u6bcf\u4e2a\u6a21\u5757\u7684 ohosArm64Main \u76ee\u5f55\u4e0b\u770b\u5230\u7c7b\u4f3c\u7684 initHook \u5c5e\u6027\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u9e3f\u8499\u7aef coil-network-ktor3 \u4e0d\u9700\u8981\u4efb\u4f55\u624b\u52a8\u914d\u7f6e\u2014\u2014&#064;EagerInitialization \u5728\u5e95\u5c42\u66ff\u4f60\u505a\u4e86\u81ea\u52a8\u6ce8\u518c\u3002<\/p>\n<h4>4.7 \u9e3f\u8499\u7279\u6709\u673a\u5236\u4e09&#xff1a;coil-gif \u7684\u539f\u751f HEIF \u52a8\u753b<\/h4>\n<p>coil-gif \u5728\u9e3f\u8499\u7aef\u505a\u4e86\u4e00\u4ef6\u5f88\u7279\u522b\u7684\u4e8b\u2014\u2014\u5b83\u4e0d\u53ea\u662f&#034;\u80fd\u8dd1&#034;&#xff0c;\u800c\u662f\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u9e3f\u8499\u539f\u751f\u89e3\u7801\u8def\u5f84\u3002\u6e90\u7801\u5728 coil-gif\/src\/ohosArm64Main\/kotlin\/coil3\/gif\/AsyncImage.kt&#xff08;\u7ea6 340 \u884c&#xff09;\u3002<\/p>\n<p>\u5148\u8bf4\u80cc\u666f&#xff1a;GIF \u52a8\u753b\u7684\u5e38\u89c4\u89e3\u7801\u65b9\u5f0f&#xff08;Android\/iOS \u901a\u7528&#xff09;\u662f&#034;Skia \u89e3\u7801\u6bcf\u4e00\u5e27 \u2192 \u5b58\u5165\u5185\u5b58 \u2192 \u5728 Compose \u7684 LaunchedEffect \u91cc\u6309\u5e27\u5ef6\u8fdf\u5237\u65b0&#034;\u3002\u8fd9\u79cd\u65b9\u5f0f\u6709\u4e24\u4e2a\u95ee\u9898&#xff1a;\u2460 HEIF \u683c\u5f0f\u5728 Skia \u4e0a\u89e3\u7801\u901f\u5ea6\u6162&#xff1b;\u2461 \u6574\u4e2a\u52a8\u753b\u6240\u6709\u5e27\u90fd\u5b58\u5185\u5b58&#xff08;val pixelBuffer &#061; ByteArray(&#8230;)&#xff09;&#xff0c;\u52a8\u56fe\u5927\u4e86\u4f1a OOM\u3002<\/p>\n<p>\u9e3f\u8499\u7aef coil-gif \u7684\u89e3\u6cd5\u662f\u539f\u751f C&#043;&#043; \u5e93\u6865\u63a5\u3002CPF \u7f16\u4e86\u4e00\u4e2a\u9e3f\u8499\u539f\u751f\u7684 C&#043;&#043; \u52a8\u6001\u5e93&#xff08;coil_gif_ohosArm64&#xff0c;\u901a\u8fc7 cinterop \u7ed1\u5b9a&#xff09;&#xff0c;\u63d0\u4f9b create_heif_animation\u3001animation_copy_frame_pixels\u3001destroy_heif_animation \u4e09\u4e2a\u51fd\u6570\u3002Kotlin \u901a\u8fc7 Kotlin\/Native \u7684 kotlinx.cinterop \u8c03\u7528\u8fd9\u4e9b C \u51fd\u6570\u3002<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u7684\u7ed3\u6784\u7279\u522b\u503c\u5f97\u5b66\u4e60\u2014\u2014\u5b83\u5c55\u793a\u4e86 Compose Multiplatform \u5728\u9e3f\u8499\u4e0a\u5982\u4f55\u505a\u5e73\u53f0\u7279\u5b9a\u7684\u6027\u80fd\u4f18\u5316&#xff0c;\u540c\u65f6\u4fdd\u6301 commonMain API \u4e0d\u53d8&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ coil-gif\/src\/ohosArm64Main\/kotlin\/coil3\/gif\/AsyncImage.kt<\/span><br \/>\n<span class=\"token comment\">\/\/ \u2014\u2014 \u9e3f\u8499\u7aef\u7684 actual \u5b9e\u73b0&#xff08;commonMain \u53ea\u6709 expect \u58f0\u660e&#xff09;<\/span><\/p>\n<p><span class=\"token annotation builtin\">&#064;Composable<\/span><br \/>\n<span class=\"token keyword\">actual<\/span> <span class=\"token keyword\">fun<\/span> <span class=\"token function\">AsyncImage<\/span><span class=\"token punctuation\">(<\/span><br \/>\n    model<span class=\"token operator\">:<\/span> String<span class=\"token punctuation\">,<\/span> contentDescription<span class=\"token operator\">:<\/span> String<span class=\"token operator\">?<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    modifier<span class=\"token operator\">:<\/span> Modifier<span class=\"token punctuation\">,<\/span><br \/>\n    onLoading<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">-&gt;<\/span> Unit<span class=\"token punctuation\">)<\/span><span class=\"token operator\">?<\/span><span class=\"token punctuation\">,<\/span> onSuccess<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">-&gt;<\/span> Unit<span class=\"token punctuation\">)<\/span><span class=\"token operator\">?<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    onError<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>Throwable<span class=\"token operator\">?<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">-&gt;<\/span> Unit<span class=\"token punctuation\">)<\/span><span class=\"token operator\">?<\/span><br \/>\n<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">val<\/span> context <span class=\"token operator\">&#061;<\/span> LocalPlatformContext<span class=\"token punctuation\">.<\/span>current<\/p>\n<p>    <span class=\"token comment\">\/\/ \u2460 \u521d\u59cb\u5316 ImageLoader \u2014\u2014 \u6ce8\u5165\u9e3f\u8499\u539f\u751f\u89e3\u7801\u5668<\/span><br \/>\n    <span class=\"token comment\">\/\/ OhosImageDecoder.Factory() \u662f\u9e3f\u8499\u7aef\u72ec\u6709\u7684 actual Decoder<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5b83\u901a\u8fc7 cinterop \u8c03\u7528 C&#043;&#043; create_heif_animation \u89e3\u7801 HEIF \u52a8\u753b<\/span><br \/>\n    <span class=\"token keyword\">val<\/span> imageLoader <span class=\"token operator\">&#061;<\/span> remember <span class=\"token punctuation\">{<\/span><br \/>\n        ImageLoader<span class=\"token punctuation\">.<\/span><span class=\"token function\">Builder<\/span><span class=\"token punctuation\">(<\/span>context<span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">.<\/span><span class=\"token function\">components<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token function\">add<\/span><span class=\"token punctuation\">(<\/span>OhosImageDecoder<span class=\"token punctuation\">.<\/span><span class=\"token function\">Factory<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n            <span class=\"token punctuation\">.<\/span><span class=\"token function\">build<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">var<\/span> animationData <span class=\"token keyword\">by<\/span> <span class=\"token function\">remember<\/span><span class=\"token punctuation\">(<\/span>model<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> mutableStateOf<span class=\"token operator\">&lt;<\/span>HeifAnimationData<span class=\"token operator\">?<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ HeifAnimationData \u5305\u542b&#xff1a;native \u53e5\u67c4 &#043; \u5bbd\u9ad8 &#043; \u5e27\u6570 &#043; \u6bcf\u5e27\u5ef6\u8fdf<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u8fd9\u4e9b\u90fd\u662f C&#043;&#043; \u5c42\u8fd4\u56de\u7684\u6570\u636e&#xff0c;Kotlin \u4fa7\u53ea\u662f\u6301\u6709<\/span><\/p>\n<p>    <span class=\"token function\">Box<\/span><span class=\"token punctuation\">(<\/span>modifier <span class=\"token operator\">&#061;<\/span> modifier<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2461 \u5148\u52a0\u8f7d\u9759\u6001\u56fe\u7247&#xff08;\u590d\u7528 Coil \u6838\u5fc3 AsyncImage&#xff09;<\/span><br \/>\n        <span class=\"token function\">CoilAsyncImage<\/span><span class=\"token punctuation\">(<\/span><br \/>\n            model <span class=\"token operator\">&#061;<\/span> model<span class=\"token punctuation\">,<\/span> imageLoader <span class=\"token operator\">&#061;<\/span> imageLoader<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">..<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            onSuccess <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> success <span class=\"token operator\">-&gt;<\/span><br \/>\n                <span class=\"token comment\">\/\/ \u2462 \u5224\u65ad\u662f\u5426\u6709\u52a8\u753b<\/span><br \/>\n                <span class=\"token keyword\">val<\/span> wrapper <span class=\"token operator\">&#061;<\/span> success<span class=\"token punctuation\">.<\/span>result<span class=\"token punctuation\">.<\/span>image <span class=\"token keyword\">as<\/span><span class=\"token operator\">?<\/span> SkiaImageWrapper<br \/>\n                <span class=\"token keyword\">val<\/span> animation <span class=\"token operator\">&#061;<\/span> wrapper<span class=\"token operator\">?<\/span><span class=\"token punctuation\">.<\/span>animation  <span class=\"token comment\">\/\/ OhosImageDecoder \u8bbe\u7f6e\u7684<\/span><br \/>\n                <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>animation <span class=\"token operator\">!&#061;<\/span> <span class=\"token keyword\">null<\/span> <span class=\"token operator\">&amp;&amp;<\/span> animation<span class=\"token punctuation\">.<\/span>frameCount <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                    <span class=\"token comment\">\/\/ \u901a\u8fc7\u5b89\u5168\u9650\u5236\u68c0\u67e5\u540e&#xff0c;\u542f\u7528\u52a8\u753b\u64ad\u653e<\/span><br \/>\n                    animationData <span class=\"token operator\">&#061;<\/span> animation<br \/>\n                <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                    <span class=\"token function\">destroy_heif_animation<\/span><span class=\"token punctuation\">(<\/span>animation<span class=\"token operator\">!!<\/span><span class=\"token punctuation\">.<\/span>handle<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ \u91ca\u653e C&#043;&#043; \u53e5\u67c4<\/span><br \/>\n                    animationData <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">null<\/span><br \/>\n                <span class=\"token punctuation\">}<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u2463 \u72ec\u7acb\u7684\u52a8\u753b\u5e27\u64ad\u653e\u5c42&#xff08;\u8986\u76d6\u5728\u9759\u6001\u56fe\u7247\u4e4b\u4e0a&#xff09;<\/span><br \/>\n        <span class=\"token function\">AnimatedOverlay<\/span><span class=\"token punctuation\">(<\/span>animationData<span class=\"token punctuation\">,<\/span> contentDescription<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ AnimatedOverlay \u7684\u6838\u5fc3\u903b\u8f91&#xff1a;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u6bcf\u5e27\u8c03 C&#043;&#043; animation_copy_frame_pixels \u2192 \u62f7\u8d1d\u5230 SkiaImage \u2192 \u8f6c Compose ImageBitmap \u2192 Image() \u663e\u793a<\/span><br \/>\n<span class=\"token comment\">\/\/ DisposableEffect(onDispose) \u91cc\u8c03 destroy_heif_animation \u91ca\u653e native \u53e5\u67c4<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u2b50 \u5b89\u5168\u9650\u5236 \u2014\u2014 \u4ece\u6e90\u7801\u91cc\u8bfb\u51fa\u6765\u7684\u786c\u7f16\u7801\u5e38\u91cf<\/span><br \/>\n<span class=\"token keyword\">private<\/span> <span class=\"token keyword\">const<\/span> <span class=\"token keyword\">val<\/span> MAX_ANIMATION_PIXELS <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1_500_000<\/span>  <span class=\"token comment\">\/\/ \u5355\u5e27\u6700\u591a 150 \u4e07\u50cf\u7d20&#xff08;\u7ea6 1224\u00d71224&#xff09;<\/span><br \/>\n<span class=\"token keyword\">private<\/span> <span class=\"token keyword\">const<\/span> <span class=\"token keyword\">val<\/span> MAX_ANIMATION_FRAMES <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">120<\/span>          <span class=\"token comment\">\/\/ \u6700\u591a 120 \u5e27<\/span><br \/>\n<span class=\"token comment\">\/\/ \u8d85\u8fc7\u9650\u5236\u65f6\u81ea\u52a8 fallback \u5230\u9759\u6001\u9996\u5e27&#xff0c;\u4e0d\u4f1a\u5d29\u6e83\u4e5f\u4e0d\u4f1a\u5403\u7206\u5185\u5b58<\/span><\/p>\n<hr \/>\n<h3>\u4e94\u3001Coil \u5728\u9e3f\u8499\u4e0a\u7684\u4f7f\u7528\u6848\u4f8b<\/h3>\n<h4>5.1 \u57fa\u7840&#xff1a;AsyncImage \u52a0\u8f7d\u7f51\u7edc\u56fe\u7247<\/h4>\n<p>\u8fd9\u662f\u4f7f\u7528 Coil \u7684\u6700\u7b80\u573a\u666f\u2014\u2014\u4e00\u884c AsyncImage \u5c31\u80fd\u628a\u7f51\u7edc\u56fe\u7247\u6e32\u67d3\u5230 Compose UI \u4e0a\u3002\u4f46\u4ee3\u7801\u91cc\u7684\u6bcf\u4e00\u5904\u7ec6\u8282\u90fd\u5f88\u91cd\u8981&#xff0c;\u6211\u9010\u884c\u89e3\u91ca&#xff1a;<\/p>\n<ul>\n<li>ImageRequest.Builder(LocalPlatformContext.current)&#xff1a;\u6784\u5efa ImageRequest&#xff0c;\u9700\u8981\u4e00\u4e2a context\u3002\u9e3f\u8499\u7aef\u7528 LocalPlatformContext \u800c\u4e0d\u662f Android \u5e38\u89c1\u7684 LocalContext\u3002\u8fd9\u662f Coil 3.3.0 \u5728 CMP \u8de8\u5e73\u53f0\u573a\u666f\u4e0b\u505a\u7684\u7edf\u4e00\u2014\u2014LocalPlatformContext \u5728 Android \u4e0a\u8fd4\u56de Activity context\u3001\u5728 iOS \u4e0a\u8fd4\u56de Window\u3001\u5728\u9e3f\u8499\u4e0a\u8fd4\u56de Ability context&#xff0c;API \u5b8c\u5168\u4e00\u81f4\u3002<\/li>\n<li>.data(url)&#xff1a;\u56fe\u7247\u6570\u636e\u6e90&#xff0c;\u53ef\u4ee5\u662f String URL\u3001File\u3001ByteArray\u3001Uri \u7b49\u3002\u9e3f\u8499\u7aef\u4e0d\u652f\u6301 Android \u7684 content:\/\/ URI&#xff08;\u9e3f\u8499\u6ca1\u6709 ContentProvider&#xff09;&#xff0c;\u4f46 HTTP\/HTTPS URL \u548c File \u8def\u5f84\u5b8c\u5168\u53ef\u7528\u3002<\/li>\n<li>.crossfade(true)&#xff1a;\u6de1\u5165\u52a8\u753b&#xff0c;\u56fe\u7247\u4ece\u900f\u660e\u6e10\u53d8\u5230\u5b8c\u5168\u663e\u793a\u3002\u9e3f\u8499\u7aef\u901a\u8fc7 Skiko Skia \u6e32\u67d3\u5c42\u5b9e\u73b0&#xff0c;\u8de8\u5e73\u53f0 API \u4e00\u81f4\u3002<\/li>\n<li>contentScale &#061; ContentScale.Crop&#xff1a;\u56fe\u7247\u88c1\u526a\u65b9\u5f0f&#xff0c;\u548c Android ImageView \u7684 scaleType&#061;&#034;centerCrop&#034; \u6548\u679c\u4e00\u6837\u3002<\/li>\n<\/ul>\n<p><span class=\"token comment\">\/\/ commonMain\/kotlin\/com\/example\/coildemo\/CoilDemo.kt<\/span><br \/>\n<span class=\"token comment\">\/\/ \u8fd9\u6bb5\u4ee3\u7801\u5b8c\u5168\u5199\u5728 commonMain \u91cc&#xff0c;Android\/iOS\/\u9e3f\u8499 Desktop \u90fd\u4f1a\u7f16\u8bd1\u901a\u8fc7<\/span><br \/>\n<span class=\"token keyword\">import<\/span> coil3<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>AsyncImage<br \/>\n<span class=\"token keyword\">import<\/span> coil3<span class=\"token punctuation\">.<\/span>request<span class=\"token punctuation\">.<\/span>ImageRequest<br \/>\n<span class=\"token keyword\">import<\/span> coil3<span class=\"token punctuation\">.<\/span>request<span class=\"token punctuation\">.<\/span>crossfade<\/p>\n<p><span class=\"token annotation builtin\">&#064;Composable<\/span><br \/>\n<span class=\"token keyword\">fun<\/span> <span class=\"token function\">CoilNetworkImageDemo<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">Column<\/span><span class=\"token punctuation\">(<\/span><br \/>\n        modifier <span class=\"token operator\">&#061;<\/span> Modifier<span class=\"token punctuation\">.<\/span><span class=\"token function\">fillMaxSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        horizontalAlignment <span class=\"token operator\">&#061;<\/span> Alignment<span class=\"token punctuation\">.<\/span>CenterHorizontally<br \/>\n    <span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">Text<\/span><span class=\"token punctuation\">(<\/span><br \/>\n            text <span class=\"token operator\">&#061;<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;Coil \u9e3f\u8499\u7f51\u7edc\u56fe\u7247\u52a0\u8f7d&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span><br \/>\n            style <span class=\"token operator\">&#061;<\/span> MaterialTheme<span class=\"token punctuation\">.<\/span>typography<span class=\"token punctuation\">.<\/span>headlineMedium<span class=\"token punctuation\">,<\/span><br \/>\n            modifier <span class=\"token operator\">&#061;<\/span> Modifier<span class=\"token punctuation\">.<\/span><span class=\"token function\">padding<\/span><span class=\"token punctuation\">(<\/span>top <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">24<\/span><span class=\"token punctuation\">.<\/span>dp<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u2b50 \u6838\u5fc3&#xff1a;AsyncImage \u2014\u2014 \u7f51\u7edc\u56fe\u7247\u4e00\u884c\u52a0\u8f7d<\/span><br \/>\n        <span class=\"token function\">AsyncImage<\/span><span class=\"token punctuation\">(<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u2460 \u6784\u5efa ImageRequest&#xff08;\u53ef\u52a0 crossfade\u3001transformation\u3001memoryCachePolicy \u7b49&#xff09;<\/span><br \/>\n            model <span class=\"token operator\">&#061;<\/span> ImageRequest<span class=\"token punctuation\">.<\/span><span class=\"token function\">Builder<\/span><span class=\"token punctuation\">(<\/span>LocalPlatformContext<span class=\"token punctuation\">.<\/span>current<span class=\"token punctuation\">)<\/span><br \/>\n                <span class=\"token punctuation\">.<\/span><span class=\"token function\">data<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/picsum.photos\/seed\/openharmony\/400\/400&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ \u968f\u673a\u56fe\u7247 API<\/span><br \/>\n                <span class=\"token punctuation\">.<\/span><span class=\"token function\">crossfade<\/span><span class=\"token punctuation\">(<\/span><span class=\"token boolean\">true<\/span><span class=\"token punctuation\">)<\/span>   <span class=\"token comment\">\/\/ \u2461 \u6de1\u5165\u52a8\u753b&#xff08;\u56fe\u7247\u52a0\u8f7d\u5b8c\u4ece\u900f\u660e\u6e10\u53d8\u5230\u4e0d\u900f\u660e&#xff09;<\/span><br \/>\n                <span class=\"token punctuation\">.<\/span><span class=\"token function\">build<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u2462 contentDescription&#xff1a;\u65e0\u969c\u788d\u63cf\u8ff0&#xff08;\u9e3f\u8499\u7684 Accessibility \u7528\u8fd9\u4e2a&#xff09;<\/span><br \/>\n            contentDescription <span class=\"token operator\">&#061;<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;OpenHarmony \u968f\u673a\u56fe\u7247&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span><br \/>\n            modifier <span class=\"token operator\">&#061;<\/span> Modifier<br \/>\n                <span class=\"token punctuation\">.<\/span><span class=\"token function\">size<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">300<\/span><span class=\"token punctuation\">.<\/span>dp<span class=\"token punctuation\">)<\/span>           <span class=\"token comment\">\/\/ \u2463 \u56fa\u5b9a\u5c3a\u5bf8 300\u00d7300 dp<\/span><br \/>\n                <span class=\"token punctuation\">.<\/span><span class=\"token function\">clip<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">RoundedCornerShape<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">16<\/span><span class=\"token punctuation\">.<\/span>dp<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span>  <span class=\"token comment\">\/\/ \u2464 \u5706\u89d2\u88c1\u526a&#xff08;Skia \u786c\u4ef6\u52a0\u901f&#xff09;<\/span><br \/>\n            contentScale <span class=\"token operator\">&#061;<\/span> ContentScale<span class=\"token punctuation\">.<\/span>Crop<span class=\"token punctuation\">,<\/span>      <span class=\"token comment\">\/\/ \u2465 \u88c1\u526a\u65b9\u5f0f&#xff1a;\u7b49\u6bd4\u88c1\u526a\u586b\u6ee1<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>&#x1f4a1; LocalPlatformContext vs LocalContext&#xff1a;LocalPlatformContext \u662f Coil 3.3.0 \u4e13\u95e8\u4e3a CMP \u5f15\u5165\u7684\u7edf\u4e00 API\u3002Android \u4e0a\u4f60\u8fd8\u80fd\u7ee7\u7eed\u7528 LocalContext&#xff08;Coil \u4f1a\u81ea\u52a8\u9002\u914d&#xff09;&#xff0c;\u4f46\u5728\u9e3f\u8499\u548c iOS \u4e0a LocalContext \u4e0d\u5b58\u5728\u3002\u8de8\u5e73\u53f0\u4ee3\u7801\u91cc\u7edf\u4e00\u7528 LocalPlatformContext \u5c31\u5bf9\u4e86\u3002<\/p>\n<h4>5.2 \u8fdb\u9636&#xff1a;LazyColumn \u56fe\u7247\u5217\u8868<\/h4>\n<p>\u8fd9\u662f\u9e3f\u8499\u5e94\u7528\u91cc\u6700\u5e38\u89c1\u7684\u573a\u666f\u2014\u2014\u65b0\u95fb\u4fe1\u606f\u6d41\u3001\u5546\u54c1\u5217\u8868\u3001\u76f8\u518c\u90fd\u9700\u8981\u4e00\u4e2a\u61d2\u52a0\u8f7d\u7684\u56fe\u7247 Grid\/List\u3002LazyColumn \u548c AsyncImage \u7684\u7ec4\u5408\u6709\u51e0\u4e2a\u5bb9\u6613\u8e29\u7684\u5751&#xff0c;\u6211\u8be6\u7ec6\u8bf4\u660e&#xff1a;<\/p>\n<p>\u7b2c\u4e00\u5751&#xff1a;items() \u5fc5\u987b\u4f20 key \u53c2\u6570\u3002LazyColumn \u7684 items \u9ed8\u8ba4\u7528\u7d22\u5f15\u4f5c key&#xff0c;\u5982\u679c\u5217\u8868\u6eda\u52a8\u65f6 item \u4f4d\u7f6e\u53d8\u5316&#xff08;\u6bd4\u5982\u6570\u636e\u6e90\u66f4\u65b0\u4e86\u3001\u6392\u5e8f\u53d8\u4e86&#xff09;&#xff0c;Compose \u4f1a\u628a\u65e7\u4f4d\u7f6e\u7684 Composable \u9519\u8bef\u590d\u7528\u7ed9\u65b0\u4f4d\u7f6e\u3002\u52a0\u4e0a key &#061; { it }&#xff08;\u7528 URL \u672c\u8eab\u4f5c key&#xff09;&#xff0c;Compose \u5c31\u80fd\u6b63\u786e\u8bc6\u522b&#034;\u8fd9\u662f\u540c\u4e00\u5f20\u56fe\u7684\u540c\u4e00\u4e2a\u4f4d\u7f6e&#034;&#xff0c;\u4e0d\u4f1a\u8bef\u56de\u6536\u3002<\/p>\n<p>\u7b2c\u4e8c\u5751&#xff1a;list \u91cc\u5173\u6389\u6de1\u5165\u52a8\u753b\u3002\u5355\u5f20\u56fe\u52a0 crossfade \u6548\u679c\u597d&#xff0c;\u4f46 LazyColumn \u5feb\u901f\u6eda\u52a8\u65f6&#xff0c;\u6bcf\u5f20\u56fe\u90fd\u6de1\u5165\u4f1a\u5bfc\u81f4\u5e27\u7387\u4e0b\u964d\u2014\u2014\u6bcf\u5f20\u56fe\u90fd\u89e6\u53d1 Skia alpha \u63d2\u503c\u3002\u5173\u6389 crossfade \u540e\u56fe\u7247\u76f4\u63a5\u663e\u793a&#xff0c;\u6eda\u52a8\u66f4\u6d41\u7545\u3002<\/p>\n<p>\u7b2c\u4e09\u5751&#xff1a;\u5185\u5b58\u7f13\u5b58\u81ea\u52a8\u751f\u6548\u3002Coil \u7684 AsyncImage \u9ed8\u8ba4\u5185\u7f6e LRU \u5185\u5b58\u7f13\u5b58&#xff08;\u9ed8\u8ba4 60 \u5f20\u3001\u9e3f\u8499\u7aef\u53ef\u914d 64MB&#xff09;\u3002LazyColumn \u6eda\u51fa\u5c4f\u5e55\u65f6 Composable dispose&#xff0c;\u6eda\u56de\u6765\u65f6 AsyncImage \u4f1a\u53d1\u73b0 URL \u5df2\u5728\u7f13\u5b58\u91cc&#xff0c;\u76f4\u63a5\u4ece\u5185\u5b58\u62ff&#xff0c;\u4e0d\u4f1a\u91cd\u65b0\u4e0b\u8f7d\u3002<\/p>\n<p><span class=\"token annotation builtin\">&#064;Composable<\/span><br \/>\n<span class=\"token keyword\">fun<\/span> <span class=\"token function\">CoilLazyImageList<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u7528 remember \u7f13\u5b58\u56fe\u7247\u5217\u8868&#xff08;\u907f\u514d\u6bcf\u6b21\u91cd\u7ec4\u91cd\u65b0\u751f\u6210&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">val<\/span> items <span class=\"token operator\">&#061;<\/span> remember <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">List<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">50<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> index <span class=\"token operator\">-&gt;<\/span><br \/>\n            <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/picsum.photos\/seed\/harmony_<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">$<\/span><span class=\"token expression\">index<\/span><\/span><span class=\"token string\">\/400\/400&#034;<\/span><\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token function\">LazyColumn<\/span><span class=\"token punctuation\">(<\/span><br \/>\n        contentPadding <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">PaddingValues<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">16<\/span><span class=\"token punctuation\">.<\/span>dp<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span>       <span class=\"token comment\">\/\/ \u5217\u8868\u6574\u4f53\u5185\u8fb9\u8ddd<\/span><br \/>\n        verticalArrangement <span class=\"token operator\">&#061;<\/span> Arrangement<span class=\"token punctuation\">.<\/span><span class=\"token function\">spacedBy<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">12<\/span><span class=\"token punctuation\">.<\/span>dp<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ \u5361\u7247\u95f4\u8ddd<\/span><br \/>\n    <span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2b50 key \u5fc5\u987b\u4f20 URL \u672c\u8eab&#xff01;<\/span><br \/>\n        <span class=\"token comment\">\/\/ LazyColumn \u7528 key \u8ffd\u8e2a item \u8eab\u4efd&#xff0c;\u786e\u4fdd\u6eda\u52a8\u56de\u6536\/\u590d\u7528\u6b63\u786e<\/span><br \/>\n        <span class=\"token function\">items<\/span><span class=\"token punctuation\">(<\/span>items<span class=\"token punctuation\">,<\/span> key <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> it <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> url <span class=\"token operator\">-&gt;<\/span><br \/>\n            <span class=\"token function\">AsyncImage<\/span><span class=\"token punctuation\">(<\/span><br \/>\n                model <span class=\"token operator\">&#061;<\/span> ImageRequest<span class=\"token punctuation\">.<\/span><span class=\"token function\">Builder<\/span><span class=\"token punctuation\">(<\/span>LocalPlatformContext<span class=\"token punctuation\">.<\/span>current<span class=\"token punctuation\">)<\/span><br \/>\n                    <span class=\"token punctuation\">.<\/span><span class=\"token function\">data<\/span><span class=\"token punctuation\">(<\/span>url<span class=\"token punctuation\">)<\/span><br \/>\n                    <span class=\"token punctuation\">.<\/span><span class=\"token function\">crossfade<\/span><span class=\"token punctuation\">(<\/span><span class=\"token boolean\">false<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ \u2b50 \u5217\u8868\u91cc\u5173\u6389\u6de1\u5165\u52a8\u753b&#xff0c;\u6eda\u52a8\u66f4\u6d41\u7545<\/span><br \/>\n                    <span class=\"token punctuation\">.<\/span><span class=\"token function\">build<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                contentDescription <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">,<\/span>  <span class=\"token comment\">\/\/ \u5217\u8868\u9879\u4e0d\u9700\u8981\u65e0\u969c\u788d\u63cf\u8ff0<\/span><br \/>\n                modifier <span class=\"token operator\">&#061;<\/span> Modifier<br \/>\n                    <span class=\"token punctuation\">.<\/span><span class=\"token function\">fillMaxWidth<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n                    <span class=\"token punctuation\">.<\/span><span class=\"token function\">aspectRatio<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1f<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ \u2460 \u5bbd\u9ad8\u6bd4 1:1&#xff08;\u6b63\u65b9\u5f62\u56fe\u7247\u5361&#xff09;<\/span><br \/>\n                    <span class=\"token punctuation\">.<\/span><span class=\"token function\">clip<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">RoundedCornerShape<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">12<\/span><span class=\"token punctuation\">.<\/span>dp<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span>  <span class=\"token comment\">\/\/ \u2461 \u5361\u7247\u5706\u89d2<\/span><br \/>\n                contentScale <span class=\"token operator\">&#061;<\/span> ContentScale<span class=\"token punctuation\">.<\/span>Crop<span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>5.3 \u5f00\u542f DMA \u52a0\u901f\u89e3\u7801<\/h4>\n<p>\u8fd9\u6b65\u53ea\u9700\u8981\u4e00\u884c\u4ee3\u7801&#xff0c;\u4f46\u5b83\u7684\u4ef7\u503c\u5f88\u9ad8\u2014\u2014\u5f00\u542f\u540e\u9e3f\u8499\u7aef JPEG\/PNG\/WebP \u56fe\u7247\u89e3\u7801\u8d70 DMA \u786c\u4ef6\u52a0\u901f&#xff0c;\u6bd4 Skia \u9ed8\u8ba4 CPU \u89e3\u7801\u5feb\u7ea6 20-40%&#xff08;\u53d6\u51b3\u4e8e\u56fe\u7247\u5927\u5c0f\u548c\u8bbe\u5907&#xff09;\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u4e0d\u9ed8\u8ba4\u5f00\u542f&#xff1f;\u4e09\u4e2a\u539f\u56e0&#xff1a;\u2460 \u9e3f\u8499 DMA API \u8fd8\u6bd4\u8f83\u65b0&#xff0c;CPF \u793e\u533a\u60f3\u8ba9\u5f00\u53d1\u8005\u81ea\u5df1\u51b3\u5b9a\u8981\u4e0d\u8981\u5c1d\u8bd5&#xff1b;\u2461 \u4e0d\u662f\u6240\u6709\u9e3f\u8499\u8bbe\u5907\u7684 DMA \u5b9e\u73b0\u90fd\u7a33\u5b9a&#xff1b;\u2462 Coil \u4e0a\u6e38\u7b56\u7565\u662f&#034;\u9ed8\u8ba4\u4fdd\u5b88\u3001\u53ef\u9009\u6fc0\u8fdb&#034;&#xff0c;\u6240\u6709\u786c\u4ef6\u52a0\u901f\u90fd\u662f opt-in\u3002<\/p>\n<p>\u91cd\u8981\u7684\u662f\u2014\u2014DMA \u89e3\u7801\u5668\u6709\u5b8c\u6574\u7684 fallback \u673a\u5236\u3002\u5982\u679c\u8bbe\u5907\u4e0d\u652f\u6301\u3001DMA API \u5f02\u5e38\u3001\u6216\u8005\u683c\u5f0f\u4e0d\u652f\u6301&#xff0c;Factory \u4f1a\u8fd4\u56de null&#xff0c;Coil \u81ea\u52a8\u8d70\u4e0b\u4e00\u4e2a\u89e3\u7801\u5668&#xff08;SkiaImageDecoder&#xff09;&#xff0c;\u4e0d\u4f1a\u5d29\u6e83\u3001\u4e0d\u4f1a\u6709\u4efb\u4f55\u53ef\u89c1\u9519\u8bef\u3002<\/p>\n<p><span class=\"token comment\">\/\/ \u5728\u9e3f\u8499\u5e94\u7528\u5165\u53e3\u521d\u59cb\u5316&#xff08;\u7c7b\u4f3c Android \u7684 Application.onCreate&#xff09;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>ui<span class=\"token punctuation\">.<\/span>res<span class=\"token punctuation\">.<\/span>OhosImageLoadConfig<\/p>\n<p><span class=\"token comment\">\/\/ \u2b50 \u4e00\u884c\u5f00\u542f\u9e3f\u8499 DMA \u786c\u4ef6\u52a0\u901f<\/span><br \/>\nOhosImageLoadConfig<span class=\"token punctuation\">.<\/span>useNativeDmaDecodeWhenAvailable <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">true<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u4e4b\u540e\u6240\u6709 AsyncImage \u52a0\u8f7d JPEG\/PNG\/WebP \u65f6&#xff1a;<\/span><br \/>\n<span class=\"token comment\">\/\/ Factory \u68c0\u67e5\u5f00\u5173\u901a\u8fc7 \u2192 \u68c0\u67e5 MIME \u7c7b\u578b\u901a\u8fc7 \u2192 \u8fd4\u56de OhosNativeDmaDecoder<\/span><br \/>\n<span class=\"token comment\">\/\/ \u5982\u679c DMA \u89e3\u7801\u5931\u8d25 \u2192 \u81ea\u52a8 fallback \u5230 Skia \u9ed8\u8ba4\u89e3\u7801\u5668<\/span><br \/>\n<span class=\"token comment\">\/\/ \u5b8c\u5168\u4e0d\u5f71\u54cd GIF\/HEIF\/SVG&#xff08;\u5b83\u4eec\u6709\u5404\u81ea\u7684\u89e3\u7801\u5668&#xff09;<\/span><\/p>\n<h4>5.4 \u81ea\u5b9a\u4e49 Transformation&#xff1a;\u5706\u5f62\u88c1\u526a &#043; \u6a21\u7cca<\/h4>\n<p>Coil \u7684 Transformation \u673a\u5236\u548c Android \u5b8c\u5168\u4e00\u81f4\u2014\u2014\u5728\u56fe\u7247&#034;\u89e3\u7801\u5b8c\u3001\u663e\u793a\u524d&#034;\u8fd9\u4e2a\u73af\u8282&#xff0c;\u7528 Skia API \u5bf9\u50cf\u7d20\u505a\u53d8\u6362\u3002\u9e3f\u8499\u7aef\u7684\u6240\u6709 Transformation \u90fd\u662f commonMain \u91cc\u7684 Skia \u64cd\u4f5c&#xff0c;\u56e0\u4e3a Skiko \u662f Skia \u7684 Kotlin\/Native \u5b8c\u6574\u7ed1\u5b9a&#xff0c;API 100% \u4e00\u81f4\u3002<\/p>\n<p>CircleCropTransformation \u5185\u90e8\u505a\u7684\u4e8b&#xff1a;\u53d6\u56fe\u7247\u8f83\u5c0f\u8fb9\u4e3a\u76f4\u5f84 \u2192 \u7528 Skia \u7684 Canvas.saveLayer \u753b\u4e00\u4e2a\u5706\u5f62 mask \u2192 \u628a\u539f\u59cb\u56fe\u7247\u88c1\u526a\u5230\u5706\u5185 \u2192 \u8fd4\u56de\u65b0\u7684 Bitmap\u3002\u9e3f\u8499\u7aef\u901a\u8fc7 Skiko \u7684 Skia C&#043;&#043; \u5b9e\u73b0\u76f4\u63a5\u8dd1\u8fd9\u4e9b\u64cd\u4f5c&#xff0c;\u6027\u80fd\u548c Android \u6301\u5e73\u3002<\/p>\n<p>BlurTransformation \u5185\u90e8\u505a\u7684\u4e8b&#xff1a;\u8c03\u7528 Skia \u7684 RuntimeShader \u6216 ImageFilters.blurImage&#xff0c;\u7528\u9ad8\u65af\u6a21\u7cca\u7b97\u6cd5\u5bf9\u50cf\u7d20\u505a\u5377\u79ef\u3002\u53c2\u6570 radius &#061; 15f \u662f\u6a21\u7cca\u534a\u5f84&#xff0c;sampling &#061; 1f \u662f\u91c7\u6837\u5bc6\u5ea6&#xff08;\u9e3f\u8499\u7aef\u4e0d\u652f\u6301 subsample&#xff0c;\u6240\u4ee5 sampling \u53ea\u80fd\u662f 1f&#xff09;\u3002<\/p>\n<p><span class=\"token annotation builtin\">&#064;Composable<\/span><br \/>\n<span class=\"token keyword\">fun<\/span> <span class=\"token function\">CoilTransformationDemo<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">Row<\/span><span class=\"token punctuation\">(<\/span><br \/>\n        modifier <span class=\"token operator\">&#061;<\/span> Modifier<span class=\"token punctuation\">.<\/span><span class=\"token function\">fillMaxWidth<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        horizontalArrangement <span class=\"token operator\">&#061;<\/span> Arrangement<span class=\"token punctuation\">.<\/span><span class=\"token function\">spacedBy<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">16<\/span><span class=\"token punctuation\">.<\/span>dp<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2460 \u5706\u5f62\u5934\u50cf \u2014\u2014 \u793e\u4ea4 App \u6700\u5e38\u7528\u7684 Transformation<\/span><br \/>\n        <span class=\"token function\">AsyncImage<\/span><span class=\"token punctuation\">(<\/span><br \/>\n            model <span class=\"token operator\">&#061;<\/span> ImageRequest<span class=\"token punctuation\">.<\/span><span class=\"token function\">Builder<\/span><span class=\"token punctuation\">(<\/span>LocalPlatformContext<span class=\"token punctuation\">.<\/span>current<span class=\"token punctuation\">)<\/span><br \/>\n                <span class=\"token punctuation\">.<\/span><span class=\"token function\">data<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/picsum.photos\/seed\/avatar\/200\/200&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n                <span class=\"token punctuation\">.<\/span><span class=\"token function\">transformations<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">CircleCropTransformation<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ Skia \u5706\u5f62\u88c1\u526a<\/span><br \/>\n                <span class=\"token punctuation\">.<\/span><span class=\"token function\">build<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            contentDescription <span class=\"token operator\">&#061;<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;\u5706\u5f62\u5934\u50cf&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span><br \/>\n            modifier <span class=\"token operator\">&#061;<\/span> Modifier<span class=\"token punctuation\">.<\/span><span class=\"token function\">size<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">100<\/span><span class=\"token punctuation\">.<\/span>dp<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ \u5706\u7684\u76f4\u5f84<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u2461 \u9ad8\u65af\u6a21\u7cca\u80cc\u666f \u2014\u2014 \u6bdb\u73bb\u7483\u6548\u679c<\/span><br \/>\n        <span class=\"token function\">AsyncImage<\/span><span class=\"token punctuation\">(<\/span><br \/>\n            model <span class=\"token operator\">&#061;<\/span> ImageRequest<span class=\"token punctuation\">.<\/span><span class=\"token function\">Builder<\/span><span class=\"token punctuation\">(<\/span>LocalPlatformContext<span class=\"token punctuation\">.<\/span>current<span class=\"token punctuation\">)<\/span><br \/>\n                <span class=\"token punctuation\">.<\/span><span class=\"token function\">data<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/picsum.photos\/seed\/bg\/800\/400&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n                <span class=\"token comment\">\/\/ radius \u662f\u6a21\u7cca\u534a\u5f84&#xff08;dp&#xff09;&#xff0c;\u8d8a\u5927\u8d8a\u7cca<\/span><br \/>\n                <span class=\"token comment\">\/\/ sampling \u662f\u91c7\u6837\u5bc6\u5ea6&#xff08;\u9e3f\u8499\u7aef\u56fa\u5b9a 1f&#xff09;<\/span><br \/>\n                <span class=\"token punctuation\">.<\/span><span class=\"token function\">transformations<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">BlurTransformation<\/span><span class=\"token punctuation\">(<\/span>radius <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">15f<\/span><span class=\"token punctuation\">,<\/span> sampling <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1f<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n                <span class=\"token punctuation\">.<\/span><span class=\"token function\">build<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            contentDescription <span class=\"token operator\">&#061;<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;\u6a21\u7cca\u80cc\u666f&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span><br \/>\n            modifier <span class=\"token operator\">&#061;<\/span> Modifier<span class=\"token punctuation\">.<\/span><span class=\"token function\">size<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">200<\/span><span class=\"token punctuation\">.<\/span>dp<span class=\"token punctuation\">,<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">.<\/span>dp<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>&#x1f9ea; \u9e3f\u8499\u7aef\u517c\u5bb9\u6027\u8bf4\u660e&#xff1a;CircleCrop\u3001RoundedCorners\u3001Blur\u3001Grayscale\u3001SquareCrop \u7b49\u5185\u7f6e Transformation \u5728 commonMain \u4e2d\u6ca1\u6709\u5e73\u53f0\u5206\u652f&#xff0c;\u9e3f\u8499\u7aef\u901a\u8fc7 Skiko Skia \u6e32\u67d3\u5c42\u81ea\u52a8\u7ee7\u627f\u3002\u5982\u679c\u9700\u8981\u81ea\u5b9a\u4e49 Transformation&#xff0c;\u4e5f\u662f\u5199\u5728 commonMain \u91cc\u7528 Skia API&#xff0c;iOS\/Desktop \u540c\u6837\u53ef\u7528\u3002<\/p>\n<h4>5.5 ImageLoader \u7f13\u5b58\u7b56\u7565\u6df1\u5ea6\u914d\u7f6e<\/h4>\n<p>Coil \u7684\u7f13\u5b58\u5206\u4e09\u5c42&#xff1a;\u5185\u5b58\u7f13\u5b58&#xff08;LRU&#xff09; \u2192 \u78c1\u76d8\u7f13\u5b58 \u2192 \u7f51\u7edc\u8bf7\u6c42\u3002\u5185\u5b58\u7f13\u5b58\u653e\u5728 Kotlin\/Native \u8fdb\u7a0b\u5806\u91cc&#xff0c;\u901f\u5ea6\u6700\u5feb\u4f46\u5bb9\u91cf\u6709\u9650&#xff1b;\u78c1\u76d8\u7f13\u5b58\u653e\u5728\u9e3f\u8499\u6c99\u7bb1\u6587\u4ef6\u7cfb\u7edf\u91cc&#xff0c;\u5bb9\u91cf\u5927\u4f46\u9700\u8981\u6587\u4ef6 IO&#xff1b;\u7f51\u7edc\u8bf7\u6c42\u6700\u6162\u3002<\/p>\n<p>\u9e3f\u8499\u8bbe\u5907\u7684 RAM \u4e00\u822c 4-8GB&#xff0c;\u7ed9 Coil 64MB LRU \u8db3\u591f&#xff08;\u5927\u7ea6 60 \u5f20 400\u00d7400 \u7684\u56fe\u7247&#xff09;\u3002\u9e3f\u8499\u6c99\u7bb1\u5b58\u50a8\u6bd4\u8f83\u5bbd\u677e&#xff08;\u5e94\u7528\u72ec\u5360\u5206\u533a&#xff0c;\u4e0d\u9700\u8981\u7533\u8bf7\u5916\u90e8\u5b58\u50a8\u6743\u9650&#xff09;&#xff0c;\u78c1\u76d8\u7f13\u5b58 256MB \u662f\u5408\u7406\u503c\u3002<\/p>\n<p>.respectCacheHeaders(false) \u7684\u542b\u4e49&#xff1a;Coil \u9ed8\u8ba4\u4f1a\u9075\u5faa HTTP Cache-Control \u5934\u6765\u51b3\u5b9a\u7f13\u5b58\u7b56\u7565&#xff0c;\u4f46\u9e3f\u8499\u7aef\u7f51\u7edc\u573a\u666f\u6bd4\u8f83\u7279\u6b8a&#xff08;\u5f31\u7f51\u3001\u7f51\u7edc\u5207\u6362\u9891\u7e41&#xff09;&#xff0c;\u8ba9 Coil \u81ea\u5df1\u7ba1\u7406\u7f13\u5b58\u7b56\u7565&#xff08;\u6309 LRU \u6dd8\u6c70&#xff09;\u901a\u5e38\u6548\u679c\u66f4\u597d\u3002<\/p>\n<p><span class=\"token comment\">\/\/ commonMain \u2014\u2014 \u5168\u5c40 ImageLoader \u914d\u7f6e<\/span><br \/>\n<span class=\"token comment\">\/\/ \u7528 remember &#043; LocalPlatformContext \u786e\u4fdd\u662f\u8de8\u5e73\u53f0 API<\/span><br \/>\n<span class=\"token annotation builtin\">&#064;Composable<\/span><br \/>\n<span class=\"token keyword\">fun<\/span> <span class=\"token function\">rememberCoilImageLoader<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">:<\/span> ImageLoader <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">val<\/span> context <span class=\"token operator\">&#061;<\/span> LocalPlatformContext<span class=\"token punctuation\">.<\/span>current<br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token function\">remember<\/span><span class=\"token punctuation\">(<\/span>context<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        ImageLoader<span class=\"token punctuation\">.<\/span><span class=\"token function\">Builder<\/span><span class=\"token punctuation\">(<\/span>context<span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u2b50 \u5185\u5b58\u7f13\u5b58&#xff1a;Kotlin\/Native \u8fdb\u7a0b\u5806\u91cc\u7684 LRU Cache<\/span><br \/>\n            <span class=\"token comment\">\/\/ maxSizeBytes&#xff1a;\u9e3f\u8499\u7aef\u7ed9 64MB&#xff08;\u5e38\u89c1\u503c 32-128MB \u53ef\u6309\u9700\u8c03&#xff09;<\/span><br \/>\n            <span class=\"token comment\">\/\/ maxSize&#xff1a;\u6700\u591a\u7f13\u5b58\u591a\u5c11\u5f20&#xff08;\u9632\u6b62\u5355\u5f20\u5927\u56fe\u5403\u5149\u7f13\u5b58&#xff09;<\/span><br \/>\n            <span class=\"token punctuation\">.<\/span><span class=\"token function\">memoryCache<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                memoryCacheConfig <span class=\"token punctuation\">{<\/span><br \/>\n                    <span class=\"token function\">maxSizeBytes<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">64<\/span> <span class=\"token operator\">*<\/span> <span class=\"token number\">1024<\/span> <span class=\"token operator\">*<\/span> <span class=\"token number\">1024<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ 64 MB LRU<\/span><br \/>\n                    <span class=\"token function\">maxSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">60<\/span><span class=\"token punctuation\">)<\/span>                      <span class=\"token comment\">\/\/ \u6700\u591a 60 \u5f20<\/span><br \/>\n                <span class=\"token punctuation\">}<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u2b50 \u78c1\u76d8\u7f13\u5b58&#xff1a;\u9e3f\u8499\u6c99\u7bb1\u6587\u4ef6\u7cfb\u7edf<\/span><br \/>\n            <span class=\"token comment\">\/\/ context.cacheDir \u5728\u9e3f\u8499\u7aef\u81ea\u52a8\u6620\u5c04\u5230\u5e94\u7528\u6c99\u7bb1\u7684 cache \u76ee\u5f55<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u4e0d\u9700\u8981\u7533\u8bf7 MANAGE_EXTERNAL_STORAGE \u6743\u9650&#xff08;\u5e94\u7528\u79c1\u6709\u5b58\u50a8&#xff09;<\/span><br \/>\n            <span class=\"token punctuation\">.<\/span><span class=\"token function\">diskCache<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                diskCacheConfig <span class=\"token punctuation\">{<\/span><br \/>\n                    <span class=\"token function\">maxSizeBytes<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">256<\/span> <span class=\"token operator\">*<\/span> <span class=\"token number\">1024<\/span> <span class=\"token operator\">*<\/span> <span class=\"token number\">1024<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ 256 MB<\/span><br \/>\n                    <span class=\"token function\">directory<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">File<\/span><span class=\"token punctuation\">(<\/span>context<span class=\"token punctuation\">.<\/span>cacheDir<span class=\"token punctuation\">,<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;coil_cache&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n                <span class=\"token punctuation\">}<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u2b50 \u7f13\u5b58\u7b56\u7565&#xff1a;\u8ba9 Coil \u81ea\u5df1\u7ba1&#xff0c;\u4e0d\u9075\u5faa HTTP Cache-Control<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u9e3f\u8499\u5f31\u7f51\u573a\u666f\u4e0b LRU \u7b56\u7565\u66f4\u53ef\u9760<\/span><br \/>\n            <span class=\"token punctuation\">.<\/span><span class=\"token function\">respectCacheHeaders<\/span><span class=\"token punctuation\">(<\/span><span class=\"token boolean\">false<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">.<\/span><span class=\"token function\">crossfade<\/span><span class=\"token punctuation\">(<\/span><span class=\"token boolean\">true<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">.<\/span><span class=\"token function\">build<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>5.6 Compose \u91cd\u7ec4\u5b89\u5168&#xff1a;ImageRequest \u7528 remember \u5305\u88f9<\/h4>\n<p>\u8fd9\u662f\u4e00\u4e2a\u5f88\u9690\u853d\u4f46\u5f71\u54cd\u5f88\u5927\u7684\u5751\u2014\u2014\u76f4\u63a5\u628a String URL \u4f20\u7ed9 AsyncImage \u65f6&#xff0c;AsyncImage \u5185\u90e8\u6bcf\u6b21\u91cd\u7ec4\u90fd\u4f1a\u521b\u5efa\u65b0\u7684 ImageRequest \u5bf9\u8c61\u3002\u6b63\u5e38\u60c5\u51b5\u4e0b\u5f71\u54cd\u4e0d\u5927&#xff0c;\u4f46\u5728\u9891\u7e41\u91cd\u7ec4\u7684\u573a\u666f\u4e0b&#xff08;\u6bd4\u5982 AnimatedVisibility \u52a8\u753b\u3001LaunchedEffect \u8f6e\u8be2\u66f4\u65b0\u3001LazyColumn \u6eda\u52a8\u56de\u8c03\u91cc\u89e6\u53d1\u7236 Composable \u91cd\u7ec4&#xff09;&#xff0c;\u6bcf\u6b21\u91cd\u7ec4\u90fd\u4f1a\u5bfc\u81f4 AsyncImage \u8ba4\u4e3a&#034;Request \u53d8\u4e86&#034;&#xff0c;\u4ece\u800c\u91cd\u65b0\u4e0b\u8f7d\u56fe\u7247\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5&#xff1a;\u628a ImageRequest \u4e5f\u653e\u8fdb remember \u91cc&#xff0c;\u8ba9\u5b83\u548c URL \u5b57\u7b26\u4e32\u89e3\u8026\u3002\u8fd9\u6837\u91cd\u7ec4\u65f6 request \u5bf9\u8c61\u4e0d\u53d8&#xff0c;AsyncImage \u5c31\u4e0d\u4f1a\u89e6\u53d1\u91cd\u65b0\u52a0\u8f7d\u3002<\/p>\n<p>\u53e6\u5916\u8981\u786e\u4fdd composeCompiler { enableStrongSkippingMode &#061; true } \u5f00\u7740\u2014\u2014\u8fd9\u8ba9 Compose \u7f16\u8bd1\u5668\u66f4\u7cbe\u786e\u5730\u5224\u65ad\u91cd\u7ec4\u8303\u56f4&#xff0c;\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684 AsyncImage \u91cd\u7ec4\u89e6\u53d1\u3002<\/p>\n<p><span class=\"token annotation builtin\">&#064;Composable<\/span><br \/>\n<span class=\"token keyword\">fun<\/span> <span class=\"token function\">CoilRecompositionSafe<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">val<\/span> context <span class=\"token operator\">&#061;<\/span> LocalPlatformContext<span class=\"token punctuation\">.<\/span>current<\/p>\n<p>    <span class=\"token comment\">\/\/ \u2b50\u2b50\u2b50 \u6838\u5fc3&#xff1a;ImageRequest \u7528 remember \u7f13\u5b58<\/span><br \/>\n    <span class=\"token comment\">\/\/ remember \u7684 key \u662f URL&#xff0c;URL \u4e0d\u53d8 \u2192 request \u5bf9\u8c61\u4e0d\u53d8<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5373\u4f7f\u5916\u5c42 Composable \u6bcf\u79d2\u91cd\u7ec4\u4e00\u6b21&#xff0c;request \u8fd8\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61<\/span><br \/>\n    <span class=\"token keyword\">val<\/span> request <span class=\"token operator\">&#061;<\/span> remember <span class=\"token punctuation\">{<\/span><br \/>\n        ImageRequest<span class=\"token punctuation\">.<\/span><span class=\"token function\">Builder<\/span><span class=\"token punctuation\">(<\/span>context<span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">.<\/span><span class=\"token function\">data<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;https:\/\/picsum.photos\/seed\/stable\/600\/600&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">.<\/span><span class=\"token function\">crossfade<\/span><span class=\"token punctuation\">(<\/span><span class=\"token boolean\">true<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token punctuation\">.<\/span><span class=\"token function\">build<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u2705 \u6b63\u786e&#xff1a;model \u4f20 remember \u8fc7\u7684 ImageRequest<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u91cd\u7ec4\u53ea\u4f1a\u89e6\u53d1 painter \u91cd\u7ed8&#xff0c;\u4e0d\u4f1a\u91cd\u65b0\u4e0b\u8f7d<\/span><br \/>\n    <span class=\"token function\">AsyncImage<\/span><span class=\"token punctuation\">(<\/span><br \/>\n        model <span class=\"token operator\">&#061;<\/span> request<span class=\"token punctuation\">,<\/span><br \/>\n        contentDescription <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        modifier <span class=\"token operator\">&#061;<\/span> Modifier<span class=\"token punctuation\">.<\/span><span class=\"token function\">size<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">300<\/span><span class=\"token punctuation\">.<\/span>dp<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u274c \u9519\u8bef\u793a\u8303&#xff08;\u4e0d\u8981\u8fd9\u6837\u5199&#xff09;&#xff1a;<\/span><br \/>\n    <span class=\"token comment\">\/\/ AsyncImage(<\/span><br \/>\n    <span class=\"token comment\">\/\/     model &#061; &#034;https:\/\/picsum.photos\/seed\/stable\/600\/600&#034;,  \/\/ \u6bcf\u6b21\u91cd\u7ec4\u521b\u5efa\u65b0 String<\/span><br \/>\n    <span class=\"token comment\">\/\/     &#8230;<\/span><br \/>\n    <span class=\"token comment\">\/\/ )<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u867d\u7136 String \u662f immutable&#xff0c;\u4f46 AsyncImage \u5185\u90e8\u4f1a\u628a\u5b83\u8f6c\u6210 ImageRequest<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u6bcf\u6b21\u91cd\u7ec4\u90fd new \u4e00\u4e2a\u65b0\u7684 ImageRequest \u5bf9\u8c61 \u2192 \u89e6\u53d1\u91cd\u65b0\u4e0b\u8f7d<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>5.7 \u56fe\u7247\u683c\u5f0f\u652f\u6301\u5168\u666f<\/h4>\n<p>\u4ee5\u4e0b\u662f\u57fa\u4e8e Skiko Skia \u6e32\u67d3\u5c42 &#043; CPF \u9e3f\u8499\u7279\u6709\u89e3\u7801\u5668\u6574\u7406\u7684\u683c\u5f0f\u652f\u6301\u60c5\u51b5&#xff1a;<\/p>\n<table>\n<tr>\u683c\u5f0f\u9e3f\u8499\u7aef\u652f\u6301\u89e3\u7801\u5668\u8def\u5f84\u5907\u6ce8<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">PNG<\/td>\n<td align=\"center\">\u2705<\/td>\n<td align=\"left\">DMA &#043; Skia<\/td>\n<td align=\"left\">DMA \u786c\u4ef6\u52a0\u901f\u652f\u6301<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">JPEG<\/td>\n<td align=\"center\">\u2705<\/td>\n<td align=\"left\">DMA &#043; Skia<\/td>\n<td align=\"left\">DMA \u786c\u4ef6\u52a0\u901f\u652f\u6301<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">WebP<\/td>\n<td align=\"center\">\u2705<\/td>\n<td align=\"left\">DMA &#043; Skia<\/td>\n<td align=\"left\">DMA \u786c\u4ef6\u52a0\u901f\u652f\u6301<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">GIF<\/td>\n<td align=\"center\">\u2705<\/td>\n<td align=\"left\">Skia<\/td>\n<td align=\"left\">\u9759\u6001\u56fe\u7247\u76f4\u63a5\u663e\u793a&#xff1b;\u52a8\u753b\u9700 coil-gif \u539f\u751f\u89e3\u7801<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">HEIF\/HEIC<\/td>\n<td align=\"center\">\u2705<\/td>\n<td align=\"left\">coil-gif OhosImageDecoder<\/td>\n<td align=\"left\">\u9e3f\u8499\u539f\u751f C&#043;&#043; \u5e93\u89e3\u7801&#xff0c;CPU \u96f6\u62f7\u8d1d<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">SVG<\/td>\n<td align=\"center\">\u2705<\/td>\n<td align=\"left\">coil-svg<\/td>\n<td align=\"left\">ServiceLoader \u2192 &#064;EagerInitialization \u81ea\u52a8\u6ce8\u518c<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">BMP<\/td>\n<td align=\"center\">\u2705<\/td>\n<td align=\"left\">Skia<\/td>\n<td align=\"left\">\u6807\u51c6\u89e3\u7801&#xff0c;\u65e0\u7279\u6b8a\u4f18\u5316<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Video Frame<\/td>\n<td align=\"center\">\u274c<\/td>\n<td align=\"left\">\u2014<\/td>\n<td align=\"left\">coil-video \u6a21\u5757\u672a\u79fb\u690d\u9e3f\u8499<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u516d\u3001\u7f16\u8bd1\u6784\u5efa\u4e0e\u771f\u673a\u8fd0\u884c<\/h3>\n<h4>6.1 DevEco Studio 26 \u7248\u91cc\u7684\u6784\u5efa<\/h4>\n<p>&#x1f4a1; \u91cd\u8981&#xff1a;Gradle \u6784\u5efa\u5fc5\u987b\u5728 DevEco Studio 26 \u7684\u5185\u7f6e\u7ec8\u7aef\u91cc\u8dd1\u3002\u7cfb\u7edf PowerShell \u9ed8\u8ba4\u7528 JBR 11&#xff08;PyCharm \u81ea\u5e26&#xff09;&#xff0c;Gradle 8.14.3 \u4f1a\u62a5 ZoneInfoFile \u7c7b\u521d\u59cb\u5316\u5931\u8d25\u3002IDE \u5185\u7f6e\u7ec8\u7aef\u81ea\u52a8\u7ee7\u627f\u4e86\u6b63\u786e\u7684 JDK 17 \u548c NDK \u73af\u5883\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030112459-6ae47e8b2e028.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u6784\u5efa\u4ea7\u7269\u7684\u5b8c\u6574\u8def\u5f84&#xff1a;<\/p>\n<ul>\n<li>.\/gradlew :composeApp:linkDebugSharedOhosArm64 \u8f93\u51fa\u5230 composeApp\/build\/bin\/ohosArm64\/debugShared\/libcoildemo.so<\/li>\n<li>\u8fd9\u4e2a .so \u6587\u4ef6\u9700\u8981\u624b\u52a8\u62f7\u8d1d\u5230\u9e3f\u8499\u5bbf\u4e3b\u5de5\u7a0b&#xff08;harmonyapp\/entry\/src\/main\/libs\/arm64-v8a\/&#xff09;<\/li>\n<li>\u9e3f\u8499\u5bbf\u4e3b\u5de5\u7a0b\u901a\u8fc7 NAPI bridge \u52a0\u8f7d\u8fd9\u4e2a .so&#xff0c;\u7136\u540e\u5728 ArkTS \u91cc\u8c03\u7528 &#064;CName \u5bfc\u51fa\u7684 Compose UI \u5165\u53e3<\/li>\n<\/ul>\n<p><span class=\"token comment\"># DevEco Studio Terminal \u91cc\u6267\u884c<\/span><\/p>\n<p><span class=\"token comment\"># \u2460 \u5982\u679c OHOS_NDK_HOME \u73af\u5883\u53d8\u91cf\u6ca1\u914d&#xff08;\u4e5f\u53ef\u4ee5\u5728\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u91cc\u8bbe\u7f6e&#xff09;<\/span><br \/>\n<span class=\"token comment\"># macOS\/Linux: export OHOS_NDK_HOME&#061;&#034;\/path\/to\/OpenHarmony\/6.0.0(20)\/native&#034;<\/span><br \/>\n<span class=\"token comment\"># Windows: \u5728\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u91cc\u52a0 OHOS_NDK_HOME<\/span><\/p>\n<p><span class=\"token comment\"># \u2461 \u6784\u5efa ohosArm64 \u5171\u4eab\u5e93&#xff08;\u751f\u6210 libcoildemo.so&#xff09;<\/span><br \/>\n<span class=\"token comment\"># linkDebugSharedOhosArm64 \u662f Kotlin\/Native \u6807\u51c6 Gradle task<\/span><br \/>\n<span class=\"token comment\"># -x test \u8df3\u8fc7\u5355\u6d4b&#xff08;ohosArm64 \u5355\u6d4b\u9700\u8981\u989d\u5916\u914d\u7f6e&#xff09;<\/span><br \/>\n<span class=\"token comment\"># &#8211;no-daemon \u7981\u7528 Gradle daemon&#xff08;\u9e3f\u8499\u7f16\u8bd1\u7ecf\u5e38\u5361\u4f4f daemon&#xff0c;\u7981\u7528\u66f4\u7a33\u5b9a&#xff09;<\/span><br \/>\n.\/gradlew :composeApp:linkDebugSharedOhosArm64 <span class=\"token parameter variable\">-x<\/span> <span class=\"token builtin class-name\">test<\/span> &#8211;no-daemon<\/p>\n<p><span class=\"token comment\"># \u2462 \u624b\u52a8\u62f7\u8d1d .so \u5230\u9e3f\u8499\u5bbf\u4e3b\u5de5\u7a0b<\/span><br \/>\n<span class=\"token comment\"># \u4ea7\u7269\u8def\u5f84&#xff1a;composeApp\/build\/bin\/ohosArm64\/debugShared\/libcoildemo.so<\/span><br \/>\n<span class=\"token comment\"># \u76ee\u6807\u8def\u5f84&#xff1a;harmonyapp\/entry\/src\/main\/libs\/arm64-v8a\/<\/span><br \/>\n<span class=\"token comment\"># \u7136\u540e\u5728 harmonyapp \u7684 build-profile.json5 \u91cc\u914d\u7f6e NAPI \u4f9d\u8d56<\/span><\/p>\n<p><span class=\"token comment\"># \u2463 DevEco Studio \u91cc\u70b9 Run \u2192 \u9009\u62e9\u771f\u673a \u2192 HAP \u81ea\u52a8\u5b89\u88c5\u8fd0\u884c<\/span><\/p>\n<h4>6.2 compose-multiplatform \u6784\u5efa\u65e5\u5fd7\u5173\u952e\u5b57<\/h4>\n<p>\u6210\u529f\u6784\u5efa\u65f6&#xff0c;\u4f60\u4f1a\u5728 Gradle \u65e5\u5fd7\u91cc\u770b\u5230\u8fd9\u4e9b\u6765\u81ea ComposePlugin \u7684\u8f93\u51fa&#xff08;\u76f4\u63a5\u4ece ComposePlugin.kt \u6e90\u7801\u7684 logger.lifecycle() \u91cc\u8bfb\u51fa\u6765\u7684&#xff09;&#xff1a;<\/p>\n<p>ComposePlugin: rendererBackend&#061;fusion-renderer,<br \/>\n    skikoVersion&#061;0.9.22.2-1.0.0,<br \/>\n    skikoOverlay&#061;true,<br \/>\n    supportedRenderBackends&#061;[fusion-renderer, skia],<br \/>\n    source&#061;default, uiCoordinate&#061;org.jetbrains.compose:ui-ohosarm64:1.9.2-1.0.0<br \/>\n    (OHOS only)<\/p>\n<p>\u9010\u5b57\u6bb5\u89e3\u91ca&#xff1a;<\/p>\n<ul>\n<li>rendererBackend&#061;fusion-renderer&#xff1a;\u6700\u7ec8\u9009\u4e2d\u7684\u6e32\u67d3\u540e\u7aef&#xff08;\u4e09\u79cd\u4f18\u5148\u7ea7&#xff1a;\u547d\u4ee4\u884c\u53c2\u6570 &gt; DSL &gt; \u9ed8\u8ba4\u503c&#xff09;<\/li>\n<li>skikoVersion&#061;0.9.22.2-1.0.0&#xff1a;\u4f7f\u7528\u7684 Skiko \u7248\u672c&#xff08;compose-plugin \u81ea\u52a8\u51b3\u5b9a&#xff0c;\u53ef\u7528 ohosSkikoVersion property \u8986\u76d6&#xff09;<\/li>\n<li>skikoOverlay&#061;true&#xff1a;compose-plugin \u4f1a\u7528\u5185\u90e8\u7248\u672c\u8986\u76d6\u4f9d\u8d56\u6811\u91cc\u7684 Skiko variant&#xff08;\u786e\u4fdd\u9e3f\u8499\u7aef\u62ff\u5230 skiko-ohosarm64 \u53d8\u4f53\u800c\u4e0d\u662f JVM\/iOS \u53d8\u4f53&#xff09;<\/li>\n<li>supportedRenderBackends&#061;[fusion-renderer, skia]&#xff1a;\u8fd9\u4e2a Compose UI artifact \u652f\u6301\u7684\u6e32\u67d3\u540e\u7aef\u5217\u8868<\/li>\n<li>uiCoordinate&#061;org.jetbrains.compose:ui-ohosarm64:1.9.2-1.0.0&#xff1a;ohosArm64 \u7684 UI artifact \u5750\u6807&#xff08;compose-plugin \u4ece artifact \u91cc\u7684 META-INF\/compose\/ohos-render-backends.properties \u8bfb\u53d6&#xff09;<\/li>\n<\/ul>\n<h4>6.3 \u9e3f\u8499\u5bbf\u4e3b\u7f51\u7edc\u6743\u9650&#xff08;\u5fc5\u914d&#xff01;&#xff09;<\/h4>\n<p>harmonyapp\/entry\/src\/main\/module.json5 \u91cc\u5fc5\u987b\u52a0\u7f51\u7edc\u6743\u9650\u3002\u8fd9\u6b65\u5f88\u5bb9\u6613\u5fd8&#xff0c;\u5fd8\u7684\u540e\u679c\u662f&#xff1a;AsyncImage \u52a0\u8f7d\u7f51\u7edc\u56fe\u7247\u53ea\u663e\u793a placeholder&#xff0c;\u4e0d\u62a5\u9519\u3001\u4e0d\u5d29\u6e83\u3001\u65e0\u4efb\u4f55\u65e5\u5fd7\u2014\u2014\u56e0\u4e3a Coil \u7684\u9519\u8bef\u56de\u8c03\u4e5f\u4e0d\u4f1a\u89e6\u53d1&#xff08;\u9e3f\u8499\u7f51\u7edc\u5c42\u5728\u7cfb\u7edf\u5c42\u9762\u5c31\u62e6\u4f4f\u4e86&#xff0c;\u4e0d\u8fd4\u56de\u7ed9\u5e94\u7528&#xff09;\u3002<\/p>\n<p>&#034;requestPermissions&#034;: [<br \/>\n  {<br \/>\n    &#034;name&#034;: &#034;ohos.permission.INTERNET&#034;,                    \/\/ \u6838\u5fc3\u7f51\u7edc\u6743\u9650&#xff08;\u5fc5\u987b&#xff09;<br \/>\n    &#034;usedInScene&#034;: [{ &#034;abilities&#034;: [&#034;EntryAbility&#034;], &#034;when&#034;: &#034;always&#034; }]<br \/>\n  },<br \/>\n  {<br \/>\n    &#034;name&#034;: &#034;ohos.permission.ACCESS_NETWORK_STATE&#034;,        \/\/ \u7f51\u7edc\u72b6\u6001\u67e5\u8be2&#xff08;\u53ef\u9009\u4f46\u63a8\u8350&#xff09;<br \/>\n    &#034;usedInScene&#034;: [{ &#034;abilities&#034;: [&#034;EntryAbility&#034;], &#034;when&#034;: &#034;always&#034; }]<br \/>\n  }<br \/>\n]<\/p>\n<h4>6.4 \u5e38\u89c1\u6784\u5efa\u9519\u8bef\u6392\u67e5<\/h4>\n<table>\n<tr>\u9519\u8bef\u4fe1\u606f\u6839\u56e0\u89e3\u51b3\u65b9\u6848<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">Could not resolve io.coil-kt.coil3:coil-compose:3.3.0<\/td>\n<td align=\"left\">CPF Nexus \u4ed3\u5e93\u6ca1\u914d\u5168&#xff08;\u4e09\u4e2a\u90fd\u8981&#xff09;<\/td>\n<td align=\"left\">add allprojects \u7684 develop\/releases\/public&#xff0c;\u6392\u6700\u524d<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Unresolved reference: ohosArm64<\/td>\n<td align=\"left\">Kotlin \u4e0d\u662f CPF patch \u7248<\/td>\n<td align=\"left\">\u786e\u8ba4 kotlin &#061; \u201c2.2.21-1.0.0\u201d<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">linkerOpts \u91cc libunwind.a \u627e\u4e0d\u5230<\/td>\n<td align=\"left\">OHOS_NDK_HOME \u73af\u5883\u53d8\u91cf\u672a\u8bbe\u7f6e<\/td>\n<td align=\"left\">\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u6216 gradle.properties<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">Could not initialize class sun.util.calendar.ZoneInfoFile<\/td>\n<td align=\"left\">\u547d\u4ee4\u884c\u7528\u4e86 JDK 11 \u800c\u4e0d\u662f JDK 17<\/td>\n<td align=\"left\">\u6539\u7528 DevEco Studio \u5185\u7f6e Terminal<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">BCV (binary-compatibility-validator) NPE<\/td>\n<td align=\"left\">\u8be5\u63d2\u4ef6\u4e0d\u8ba4\u8bc6 ohosArm64 KonanTarget<\/td>\n<td align=\"left\">coil-oh \u91cc\u628a\u6240\u6709 subprojects \u52a0\u4e86 ignoredProjects&#xff0c;\u4f60\u81ea\u5df1\u7684\u9879\u76ee\u53ef\u4ee5\u52a0 ignoredProjects &#043;&#061; &#034;\u4f60\u7684\u6a21\u5757\u540d&#034; \u6216\u7981\u7528 BCV<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u771f\u673a AsyncImage \u53ea\u663e\u793a placeholder<\/td>\n<td align=\"left\">\u5fd8\u4e86\u52a0 INTERNET \u6743\u9650<\/td>\n<td align=\"left\">module.json5 \u8865\u914d\u7f6e&#xff0c;\u5378\u8f7d\u91cd\u88c5\u5e94\u7528<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">DMA \u89e3\u7801\u5668\u4e0d\u751f\u6548<\/td>\n<td align=\"left\">useNativeDmaDecodeWhenAvailable \u9ed8\u8ba4 false<\/td>\n<td align=\"left\">\u5e94\u7528\u5165\u53e3\u624b\u52a8\u8bbe true<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">GIF \u52a8\u753b\u4e0d\u52a8<\/td>\n<td align=\"left\">\u6ca1\u52a0 coil-gif \u4f9d\u8d56<\/td>\n<td align=\"left\">implementation(libs.coil.gif)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5b9e\u6d4b\u6548\u679c\u5982\u56fe&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030112500-6ae47e8c408e1.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030112500-6ae47e8c7e7ec.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<hr \/>\n<h3>\u4e03\u3001\u6e90\u7801\u63a2\u67e5&#xff1a;ohosArm64Main \u76ee\u5f55\u5168\u89e3<\/h3>\n<p>\u6211 clone \u4e86 CPF-KMP-CMP\/coil \u7684 main-3.3.0-OH \u5206\u652f&#xff0c;\u786e\u8ba4 ohosArm64Main \u4e0b\u6709 7 \u4e2a Kotlin \u6587\u4ef6\u3002\u5bf9\u6bd4 Android\/iOS \u7b49\u5e73\u53f0\u7684 actual \u5b9e\u73b0&#xff08;\u6bd4\u5982 Android \u7684 AsyncImagePainter.android.kt\u3001iOS \u7684 GIF actual&#xff09;&#xff0c;\u9e3f\u8499\u7aef\u7684\u6587\u4ef6\u6570\u91cf\u4e0d\u591a&#xff0c;\u4f46\u6bcf\u4e2a\u90fd\u6709\u660e\u786e\u7684\u8bbe\u8ba1\u76ee\u7684&#xff1a;<\/p>\n<p>coil-core\/src\/ohosArm64Main\/kotlin\/coil3\/<br \/>\n\u251c\u2500\u2500 RealImageLoader.ohosArm64.kt        # \u6ce8\u518c OhosNativeDmaDecoder.Factory()&#xff08;~19 \u884c&#xff0c;\u5f88\u8584\u7684\u4e00\u5c42&#xff09;<br \/>\n\u251c\u2500\u2500 decode\/<br \/>\n\u2502   \u2514\u2500\u2500 OhosNativeDmaDecoder.kt          # \u2b50 \u9e3f\u8499 DMA \u786c\u4ef6\u89e3\u7801\u5668&#xff08;~150 \u884c&#xff0c;\u6838\u5fc3\u4f18\u5316&#xff09;<br \/>\n\u2514\u2500\u2500 util\/<br \/>\n    \u2514\u2500\u2500 utils.ohosArm64.kt              # WeakReference typealias&#xff08;~5 \u884c&#xff0c;\u89e3\u51b3 Kotlin\/Native \u5e73\u53f0\u5dee\u5f02&#xff09;<\/p>\n<p>coil-gif\/src\/ohosArm64Main\/kotlin\/coil3\/gif\/<br \/>\n\u2514\u2500\u2500 AsyncImage.kt                        # \u2b50 \u9e3f\u8499\u7aef actual AsyncImage &#043; HEIF \u539f\u751f\u89e3\u7801&#xff08;~340 \u884c&#xff0c;\u6700\u590d\u6742\u7684\u9e3f\u8499\u7279\u6709\u4ee3\u7801&#xff09;<\/p>\n<p>coil-network-ktor2\/src\/ohosArm64Main\/<br \/>\n\u2514\u2500\u2500 &#8230;\/KtorNetworkFetcherServiceLoaderTarget.ohosArm64.kt  # &#064;EagerInitialization \u81ea\u52a8\u6ce8\u518c<\/p>\n<p>coil-network-ktor3\/src\/ohosArm64Main\/<br \/>\n\u2514\u2500\u2500 &#8230;\/KtorNetworkFetcherServiceLoaderTarget.ohosArm64.kt  # &#064;EagerInitialization \u81ea\u52a8\u6ce8\u518c<\/p>\n<p>coil-svg\/src\/ohosArm64Main\/<br \/>\n\u2514\u2500\u2500 &#8230;\/SvgDecoderServiceLoaderTarget.ohosArm64.kt         # &#064;EagerInitialization \u81ea\u52a8\u6ce8\u518c<\/p>\n<h4>coil-oh \u7684 hierarchy template \u8bbe\u8ba1\u89e3\u8bfb<\/h4>\n<p>CPF \u7ed9 coil \u5355\u72ec\u5b9a\u4e49\u4e86 KMP \u5c42\u7ea7\u6a21\u677f&#xff08;buildSrc\/hierarchyTemplate.kt&#xff09;&#xff0c;\u628a ohos \u4ece Apple native \u7ec4\u91cc\u72ec\u7acb\u51fa\u6765\u3002\u8fd9\u4e2a\u8bbe\u8ba1\u975e\u5e38\u91cd\u8981\u2014\u2014\u5982\u679c\u4e0d\u72ec\u7acb&#xff0c;ohosArm64 \u4f1a\u610f\u5916\u7ee7\u627f iOS\/macOS \u7684\u5e73\u53f0\u7279\u5b9a\u4ee3\u7801&#xff08;\u6bd4\u5982 Android \u4e0a\u6709 NSURLMapper \u662f iOS \u4e13\u5c5e\u7684 URL \u89e3\u6790\u5668&#xff0c;\u4e0d\u9002\u5408\u9e3f\u8499&#xff09;\u3002<\/p>\n<p><span class=\"token comment\">\/\/ hierarchyTemplate.kt \u2014\u2014 \u6211\u52a0\u4e86\u4e2d\u6587\u6ce8\u91ca\u8bf4\u660e\u8bbe\u8ba1\u610f\u56fe<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u5173\u952e\u8bbe\u8ba1&#xff1a;ohos \u4e0d\u7ee7\u627f Apple \u4e13\u5c5e\u4ee3\u7801<\/span><br \/>\n<span class=\"token keyword\">private<\/span> <span class=\"token keyword\">fun<\/span> KotlinHierarchyBuilder<span class=\"token punctuation\">.<\/span><span class=\"token function\">groupNative<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">group<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;native&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2b50\u2b50\u2b50 \u8fd9\u4e2a\u6761\u4ef6\u662f\u6838\u5fc3&#xff01;<\/span><br \/>\n        <span class=\"token comment\">\/\/ withCompilations \u7b5b\u9009\u6240\u6709 Kotlin\/Native target<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u4f46\u7528 !it.target.name.startsWith(&#034;ohos&#034;) \u6392\u9664\u4e86 ohosArm64<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u6548\u679c&#xff1a;ohosArm64 \u4e0d\u4f1a\u7ee7\u627f group(&#034;apple&#034;) \u91cc\u7684\u4efb\u4f55\u4ee3\u7801<\/span><br \/>\n        withCompilations <span class=\"token punctuation\">{<\/span><br \/>\n            it<span class=\"token punctuation\">.<\/span>platformType <span class=\"token operator\">&#061;&#061;<\/span> KotlinPlatformType<span class=\"token punctuation\">.<\/span>native<br \/>\n            <span class=\"token operator\">&amp;&amp;<\/span> <span class=\"token operator\">!<\/span>it<span class=\"token punctuation\">.<\/span>target<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">.<\/span><span class=\"token function\">startsWith<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;ohos&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token function\">group<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;apple&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token function\">withApple<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">..<\/span><span class=\"token punctuation\">.<\/span> <span class=\"token punctuation\">}<\/span>  <span class=\"token comment\">\/\/ iOS\/macOS \u4e13\u5c5e\u7ec4<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ ohos \u72ec\u7acb\u7ec4<\/span><br \/>\n<span class=\"token keyword\">private<\/span> <span class=\"token keyword\">fun<\/span> KotlinHierarchyBuilder<span class=\"token punctuation\">.<\/span><span class=\"token function\">groupOhos<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">group<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;ohos&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2b50 \u4efb\u4f55 target \u540d\u4ee5 &#034;ohos&#034; \u5f00\u5934\u7684&#xff08;ohosArm64\u3001ohosX64 \u672a\u6765\u6269\u5c55&#xff09;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u90fd\u88ab\u5f52\u5230\u8fd9\u4e2a\u72ec\u7acb\u7684\u7ec4<\/span><br \/>\n        withCompilations <span class=\"token punctuation\">{<\/span> it<span class=\"token punctuation\">.<\/span>target<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">.<\/span><span class=\"token function\">startsWith<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;ohos&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u7ee7\u627f\u5173\u7cfb\u56fe&#xff08;\u7b80\u5316&#xff09;&#xff1a;<\/span><br \/>\n<span class=\"token comment\">\/\/ commonMain \u2192 \u6240\u6709 target \u90fd\u7ee7\u627f<\/span><br \/>\n<span class=\"token comment\">\/\/   \u251c\u2500\u2500 ohos \u7ec4&#xff1a;ohosArm64 \u2192 \u7ee7\u627f nonAndroid&#xff08;Skiko&#xff09;\u4f46\u4e0d\u7ee7\u627f apple \u4e13\u5c5e<\/span><br \/>\n<span class=\"token comment\">\/\/   \u2514\u2500\u2500 native \u7ec4&#xff08;\u975e ohos&#xff09;&#xff1a;iOS\/macOS \u2192 \u7ee7\u627f apple \u4e13\u5c5e\u4ee3\u7801<\/span><\/p>\n<p>\u8fd9\u610f\u5473\u7740\u2014\u2014ohosArm64 \u7ee7\u627f commonMain &#043; nonAndroidMain&#xff08;Skiko&#xff09;&#043; ohos \u72ec\u7acb\u7ec4&#xff0c;\u4e0d\u4f1a\u610f\u5916\u5f15\u5165 iOS\/macOS \u7684\u5e73\u53f0\u7279\u5b9a\u4ee3\u7801&#xff08;\u6bd4\u5982 NSURLMapper\u3001Lifecycle \u6865\u63a5\u7b49&#xff09;\u3002CPF \u793e\u533a\u901a\u8fc7\u8fd9\u4e2a hierarchy template \u89e3\u51b3\u4e86&#034;\u9e3f\u8499\u548c iOS \u90fd\u662f Kotlin\/Native \u4f46\u5e73\u53f0 API \u5b8c\u5168\u4e0d\u540c&#034;\u7684\u7ee7\u627f\u51b2\u7a81\u3002<\/p>\n<hr \/>\n<h3>\u516b\u3001FAQ<\/h3>\n<h4>Q1&#xff1a;Coil \u9e3f\u8499\u4e0a\u80fd\u52a0\u8f7d\u54ea\u4e9b\u56fe\u7247\u6e90&#xff1f;<\/h4>\n<p>A&#xff1a;commonMain API \u4e0e Android\/iOS \u5b8c\u5168\u4e00\u81f4\u2014\u2014HTTP\/HTTPS URL\u3001\u672c\u5730\u6587\u4ef6\u8def\u5f84\u3001ByteArray\u3001Drawable resource\u3002\u9e3f\u8499\u7aef\u7279\u6709\u7684&#xff1a;\u4e0d\u652f\u6301 Android \u7684 content:\/\/ URI \u548c Android Assets&#xff08;\u9e3f\u8499\u6ca1\u6709 ContentProvider \u4e5f\u6ca1\u6709 android \u8d44\u6e90\u7cfb\u7edf&#xff09;&#xff0c;\u6c99\u7bb1\u6587\u4ef6\u7528 Context.cacheDir \/ Context.filesDir\u3002<\/p>\n<h4>Q2&#xff1a;ohosX64 target \u652f\u6301\u5417&#xff1f;<\/h4>\n<p>A&#xff1a;compose-multiplatform \u7684 hierarchy template \u9884\u7559\u4e86 ohosX64&#xff08;\u901a\u8fc7 it.target.name.startsWith(&#034;ohos&#034;) \u901a\u914d&#xff09;&#xff0c;cmp-oh \u4ed3\u5e93\u91cc\u4e5f\u6709 ohosX64Main \u76ee\u5f55&#xff08;ResourceEnvironment\u3001ResourceReader \u7b49\u6e90\u7801&#xff09;\u3002\u4f46 coil-oh \u7684 addAllMultiplatformTargets() \u76ee\u524d\u53ea\u58f0\u660e\u4e86 ohosArm64()&#xff0c;\u6ca1\u6709 ohosX64()\u3002\u5982\u679c\u4f60\u9700\u8981\u6a21\u62df\u5668\u8c03\u8bd5&#xff0c;\u53ef\u4ee5\u81ea\u5df1\u5728 kotlin {} \u5757\u91cc\u52a0 ohosX64 { binaries.sharedLib { baseName &#061; &#034;coildemo&#034; } }\u3002<\/p>\n<h4>Q3&#xff1a;DMA \u89e3\u7801\u5668\u6709\u4ec0\u4e48\u597d\u5904&#xff1f;\u4e3a\u4ec0\u4e48\u9ed8\u8ba4\u5173\u95ed&#xff1f;<\/h4>\n<p>A&#xff1a;DMA&#xff08;Direct Memory Access&#xff09;\u7ed5\u8fc7 CPU \u76f4\u63a5\u628a\u56fe\u7247\u6570\u636e\u4ece\u5185\u5b58\u62f7\u8d1d\u5230 GPU \u663e\u5b58&#xff0c;\u6bd4\u5e38\u89c4 Skia CPU \u89e3\u7801\u5feb\u7ea6 20-40%&#xff0c;\u5185\u5b58\u62f7\u8d1d\u4e5f\u5c11\u4e00\u6b21\u3002\u9ed8\u8ba4\u5173\u95ed\u4e09\u4e2a\u539f\u56e0&#xff1a;\u2460 \u9e3f\u8499 DMA API \u8f83\u65b0&#xff08;\u968f HarmonyOS SDK 6.0.0 \u5f15\u5165&#xff09;&#xff0c;CPF \u793e\u533a\u8fd8\u5728\u6536\u96c6\u53cd\u9988&#xff1b;\u2461 \u4e0d\u662f\u6240\u6709\u9e3f\u8499\u8bbe\u5907\u7684 DMA \u5b9e\u73b0\u90fd\u7a33\u5b9a&#xff1b;\u2462 Coil \u4e0a\u6e38\u7b56\u7565\u662f\u9ed8\u8ba4\u4fdd\u5b88\u2014\u2014\u65b0\u786c\u4ef6\u52a0\u901f\u603b\u662f opt-in \u800c\u4e0d\u662f\u9ed8\u8ba4\u5f00\u542f&#xff0c;\u907f\u514d\u7ebf\u4e0a\u5d29\u3002\u5f00\u542f\u5f88\u7b80\u5355&#xff1a;OhosImageLoadConfig.useNativeDmaDecodeWhenAvailable &#061; true\u3002<\/p>\n<h4>Q4&#xff1a;fusion-renderer \u548c skia \u4e24\u79cd\u6e32\u67d3\u540e\u7aef\u6709\u4ec0\u4e48\u533a\u522b&#xff1f;<\/h4>\n<p>A&#xff1a;\u8fd9\u662f compose-multiplatform \u9e3f\u8499\u7aef\u7684\u4e24\u6761\u6e32\u67d3\u8def\u5f84&#xff1a;<\/p>\n<ul>\n<li>fusion-renderer&#xff08;\u9ed8\u8ba4&#xff09;&#xff1a;\u57fa\u4e8e\u9e3f\u8499\u539f\u751f OpenGL ES&#xff08;EGL&#xff09;&#043; Skiko \u6865\u63a5\u5c42\u3002\u9e3f\u8499\u7cfb\u7edf\u7ea7 GPU \u4f18\u5316&#xff0c;\u6027\u80fd\u66f4\u597d&#xff0c;\u6709\u9e3f\u8499\u7cfb\u7edf\u7684\u56fe\u5f62\u6808\u515c\u5e95\u3002compose-plugin \u5185\u7f6e\u7684\u9ed8\u8ba4\u540e\u7aef\u3002<\/li>\n<li>skia&#xff1a;\u7eaf Skia \u8f6f\u4ef6\u6e32\u67d3&#xff08;\u901a\u8fc7 Skiko \u7684 CPU backend&#xff09;\u3002\u517c\u5bb9\u6027\u66f4\u597d&#xff08;\u4efb\u4f55\u8bbe\u5907\u90fd\u80fd\u8dd1&#xff09;&#xff0c;\u4f46\u6ca1\u6709\u5229\u7528\u9e3f\u8499 GPU \u52a0\u901f\u3002\u9002\u5408\u8c03\u8bd5 fusion-renderer \u517c\u5bb9\u6027\u95ee\u9898\u65f6\u4f7f\u7528\u3002<\/li>\n<li>\u5207\u6362\u65b9\u5f0f&#xff1a;compose { ohos { skia() } } \u6216\u547d\u4ee4\u884c -PrendererBackend&#061;skia\u3002\u914d\u7f6e\u4f18\u5148\u7ea7&#xff1a;\u547d\u4ee4\u884c\u53c2\u6570 &gt; compose DSL &gt; \u9ed8\u8ba4 fusion-renderer\u3002<\/li>\n<\/ul>\n<h4>Q5&#xff1a;\u4e3a\u4ec0\u4e48\u9e3f\u8499\u7aef\u7528 &#064;EagerInitialization \u800c\u4e0d\u662f ServiceLoader&#xff1f;<\/h4>\n<p>A&#xff1a;Java \u7684 ServiceLoader \u673a\u5236\u4f9d\u8d56 classpath \u626b\u63cf&#xff08;META-INF\/services\/com.example.Interface \u914d\u7f6e\u6587\u4ef6&#xff09;&#xff0c;\u5728 Kotlin\/Native \u91cc\u5b8c\u5168\u4e0d\u53ef\u7528\u2014\u2014\u7f16\u8bd1\u4ea7\u7269\u662f\u5355\u4e2a\u4e8c\u8fdb\u5236&#xff08;.so \u6216 .kexe&#xff09;&#xff0c;\u6ca1\u6709 classpath \u6982\u5ff5\u4e5f\u6ca1\u6709 META-INF \u76ee\u5f55\u3002Kotlin\/Native 1.7.20 \u5f15\u5165\u4e86 &#064;EagerInitialization&#xff1a;\u7a0b\u5e8f\u542f\u52a8\u65f6&#xff08;Kotlin\/Native \u8fd0\u884c\u65f6\u521d\u59cb\u5316\u9636\u6bb5&#xff09;\u81ea\u52a8\u6267\u884c\u5e26\u6b64\u6ce8\u89e3\u7684\u9876\u5c42\u5c5e\u6027\u521d\u59cb\u5316\u4ee3\u7801\u3002coil-network-ktor3\u3001coil-svg\u3001coil-network-ktor2 \u90fd\u7528\u8fd9\u4e2a\u673a\u5236\u505a\u81ea\u52a8\u6ce8\u518c\u3002Android \u4e0a\u8fd8\u80fd\u770b\u5230 ServiceLoader \u6587\u4ef6&#xff0c;\u9e3f\u8499\u7aef\u770b &#064;EagerInitialization val initHook\u3002<\/p>\n<h4>Q6&#xff1a;coil-gif \u5728\u9e3f\u8499\u7aef\u6709\u4ec0\u4e48\u7279\u522b\u4e4b\u5904&#xff1f;<\/h4>\n<p>A&#xff1a;coil-gif \u7684 ohosArm64Main \u6709\u4e00\u4e2a\u5b8c\u6574\u7684 actual AsyncImage \u5b9e\u73b0&#xff08;\u7ea6 340 \u884c&#xff09;&#xff0c;\u800c Android\/iOS \u7aef\u53ea\u662f\u7b80\u5355\u8c03\u7528 Skia\u3002\u9e3f\u8499\u7aef\u7279\u522b\u505a\u4e86&#xff1a;<\/p>\n<li>\u901a\u8fc7 cinterop \u8c03\u7528\u9e3f\u8499\u539f\u751f C&#043;&#043; \u5e93&#xff08;create_heif_animation \/ animation_copy_frame_pixels&#xff09;\u505a HEIF \u52a8\u56fe\u89e3\u7801<\/li>\n<li>\u901a\u8fc7 LaunchedEffect &#043; DisposableEffect \u9a71\u52a8\u52a8\u753b\u5e27\u5faa\u73af&#xff0c;\u5e76\u5728 Composable dispose \u65f6\u91ca\u653e native \u53e5\u67c4&#xff08;\u9632\u5185\u5b58\u6cc4\u6f0f&#xff09;<\/li>\n<li>\u8bbe\u7f6e\u4e86\u5b89\u5168\u9650\u5236&#xff08;120 \u5e27\u3001150 \u4e07\u50cf\u7d20&#xff09;&#xff0c;\u8d85\u8fc7\u65f6\u81ea\u52a8 fallback \u5230\u9759\u6001\u9996\u5e27<\/li>\n<h4>Q7&#xff1a;OHOS_NDK_HOME \u5fc5\u987b\u914d\u5417&#xff1f;<\/h4>\n<p>A&#xff1a;\u662f\u7684\u3002\u4e24\u4e2a\u5730\u65b9\u4f9d\u8d56\u5b83&#xff1a;<\/p>\n<li>coil-oh \u7684 linkerOpts \u786c\u7f16\u7801\u4e86 ${OHOS_NDK_HOME}\/native\/llvm\/lib\/aarch64-linux-ohos\/libunwind.a\u2014\u2014\u8fd9\u662f LLVM \u6808\u56de\u6eaf\u9759\u6001\u5e93&#xff0c;Kotlin\/Native \u5f02\u5e38\u6253\u5370\u5fc5\u987b\u94fe\u63a5\u5b83<\/li>\n<li>compose-multiplatform \u7684 OhosNativeLinkerConfigurator \u4f1a\u7528 NDK \u7684 -lnative_drawing\u3001-licu\u3001-limage_packer \u7b49\u7cfb\u7edf\u5e93 \u4e0d\u914d\u7684\u8bdd linkDebugSharedOhosArm64 \u4f1a\u62a5 unresolved library libunwind.a\u3002<\/li>\n<h4>Q8&#xff1a;compose {} ohos DSL \u7684\u4f18\u5148\u7ea7\u662f\u600e\u6837\u7684&#xff1f;<\/h4>\n<p>A&#xff1a;compose-multiplatform ComposePlugin.kt \u6e90\u7801\u91cc resolveOhosBackendConfig() \u51fd\u6570\u660e\u786e\u5199\u4e86\u4e09\u79cd\u4f18\u5148\u7ea7&#xff08;\u4ece\u9ad8\u5230\u4f4e&#xff09;&#xff1a;<\/p>\n<li>\u547d\u4ee4\u884c\u53c2\u6570&#xff1a;.\/gradlew linkDebugSharedOhosArm64 -PrendererBackend&#061;skia<\/li>\n<li>DSL \u5757&#xff1a;compose { ohos { skia() } } \u6216 compose { ohos { fusionRenderer() } }<\/li>\n<li>\u9ed8\u8ba4\u503c&#xff1a;fusion-renderer&#xff08;\u81ea\u52a8\u4f7f\u7528 compose-plugin \u5185\u7f6e\u7684 Skiko \u7248\u672c&#xff09;<\/li>\n<h4>Q9&#xff1a;\u9e3f\u8499\u7aef Coil \u4f1a\u5185\u5b58\u6cc4\u6f0f\u5417&#xff1f;<\/h4>\n<p>A&#xff1a;\u6b63\u5e38\u4f7f\u7528\u4e0d\u4f1a\u3002\u539f\u56e0&#xff1a;<\/p>\n<ul>\n<li>AsyncImage \u548c rememberAsyncImagePainter \u81ea\u5e26 Composable \u751f\u547d\u5468\u671f\u611f\u77e5&#xff08;DisposableEffect \u5728 dispose \u65f6\u81ea\u52a8\u53d6\u6d88\u534f\u7a0b &#043; \u91ca\u653e\u5185\u5b58&#xff09;<\/li>\n<li>coil-gif \u7684 actual AsyncImage \u7528 DisposableEffect(onDispose) \u7ed1\u5b9a native \u53e5\u67c4\u91ca\u653e&#xff08;destroy_heif_animation(handle)&#xff09;<\/li>\n<li>ohosArm64Main \u7684 utils.ohosArm64.kt \u628a WeakReference typealias \u5230 kotlin.native.ref.WeakReference\u2014\u2014Kotlin\/Native \u7684 GC \u6b63\u786e\u652f\u6301\u5f31\u5f15\u7528&#xff0c;\u4e0d\u4f1a\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f<\/li>\n<li>OhosNativeDmaDecoder \u5931\u8d25\u65f6\u81ea\u52a8\u8fd4\u56de null \u8d70 fallback&#xff0c;\u4e0d\u4f1a\u5361\u4f4f\u5f02\u5e38\u89e3\u7801\u6d41\u7a0b<\/li>\n<li>ImageLoader \u5efa\u8bae\u7528 Application context&#xff08;LocalPlatformContext \u81ea\u52a8\u6620\u5c04&#xff09;&#xff0c;\u907f\u514d\u6301\u6709 Activity context<\/li>\n<\/ul>\n<h4>Q10&#xff1a;\u5982\u4f55\u8ddf\u8fdb\u4e0a\u6e38\u7248\u672c\u66f4\u65b0&#xff1f;<\/h4>\n<p>A&#xff1a;CPF-KMP-CMP \u7684\u7b56\u7565\u662f\u5148\u7b49\u4e0a\u6e38\u53d1\u5e03\u7a33\u5b9a\u7248\u518d\u9002\u914d\u9e3f\u8499\u3002\u4f60\u53ef\u4ee5&#xff1a;<\/p>\n<li>\u5173\u6ce8\u4e0a\u6e38 coil-kt\/coil \u7684 release \u52a8\u6001<\/li>\n<li>Fork CPF-KMP-CMP\/coil \u2192 \u5347\u7ea7 libs.versions.toml \u7248\u672c\u53f7 \u2192 \u68c0\u67e5 ohosArm64Main \u6e90\u6587\u4ef6\u662f\u5426\u9700\u8981\u9002\u914d\u65b0\u7248\u672c API \u2192 \u63d0\u4ea4 PR<\/li>\n<li>CPF \u4ed3\u5e93\u7684 CI \u4f1a\u81ea\u52a8\u8dd1 ohosArm64 \u4ea4\u53c9\u7f16\u8bd1&#xff0c;\u786e\u4fdd\u4f60\u7684\u6539\u52a8\u4e0d\u4f1a\u7834\u574f\u9e3f\u8499\u6784\u5efa<\/li>\n<hr \/>\n<h3>\u4e5d\u3001\u793e\u533a\u5f15\u5bfc<\/h3>\n<p>\u6b22\u8fce\u52a0\u5165 KMP&amp;CMP \u9e3f\u8499\u793e\u533a&#xff1a;https:\/\/atomgit.com\/CPF-KMP-CMP<\/p>\n<p>CPF-KMP-CMP \u7ec4\u7ec7\u662f\u9e3f\u8499\u4e0a Compose Multiplatform \u751f\u6001\u7684\u6838\u5fc3\u7ef4\u62a4\u8005&#xff0c;\u76ee\u524d\u5df2\u6709 88 \u4e2a\u4ed3\u5e93&#xff0c;\u8986\u76d6&#xff1a;<\/p>\n<table>\n<tr>\u4ed3\u5e93tag\u9e3f\u8499\u9002\u914d\u4eae\u70b9<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">compose-multiplatform<\/td>\n<td align=\"left\">develop-1.9.2-OH<\/td>\n<td align=\"left\">Compose Plugin &#043; fusion-renderer \u9ed8\u8ba4\u540e\u7aef &#043; compose{ohos{}} DSL &#043; \u4e09\u6e90 Nexus<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">compose-multiplatform-core<\/td>\n<td align=\"left\">v1.9.2-1.1.0<\/td>\n<td align=\"left\">Skiko \u4ea4\u53c9\u7f16\u8bd1 ohosArm64\/ohosX64 &#043; Skia \u6e32\u67d3\u8fd0\u884c\u65f6<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">coil<\/td>\n<td align=\"left\">main-3.3.0-OH<\/td>\n<td align=\"left\">OhosNativeDmaDecoder \u786c\u4ef6\u52a0\u901f &#043; coil-gif \u539f\u751f HEIF \u52a8\u753b &#043; ServiceLoader\u2192&#064;EagerInitialization &#043; hierarchy template ohos \u72ec\u7acb\u7ec4<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">compottie<\/td>\n<td align=\"left\">main-2.0.2-OH<\/td>\n<td align=\"left\">Lottie \u52a8\u753b\u9e3f\u8499\u9002\u914d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5982\u679c\u4f60\u5728\u9002\u914d\u8fc7\u7a0b\u4e2d\u7528\u5230\u4e86 AI \u8f85\u52a9\u5de5\u5177&#xff0c;\u63a8\u8350 \u7801\u9053&#xff08;CodeArts&#xff09;\u4e13\u5c5e\u901a\u9053&#xff1a; https:\/\/developer.huaweicloud.com\/codeartsco.html?source&#061;dmzntgwatomgit1&amp;sourcead&#061;dmzntgwatomgiths<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6846\u67b6&#xff1a;Compose Multiplatform v1.9.2-1.0.0  OpenHarmony SDK 6.0.0(20) \u5e93\u540d\u79f0&#xff1a;Coil 3.3.0&#xff08;Compose Multiplatform \u56fe\u7247\u52a0\u8f7d\u5e93&#xff09; \u9e3f\u8499\u9002\u914d\u4ed3\u5e93&#xff1a;CPF-KMP-CMP\/coil \u9002\u914d\u5206\u652f&#xff1a;main-3.3.0-OH&#xff08;\u9e3f\u8499\u5b9a\u5236\u7248&#xff09; \u7248\u672c&#xff1a;v3.3.0-1.0.0 Ma<\/p>\n","protected":false},"author":2,"featured_media":119952,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[12392,280,4361,67,43,44],"topic":[],"class_list":["post-119956","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-12392","tag-harmonyos","tag-openharmony","tag-67","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>CMP for OpenHarmony \u5b9e\u6218\uff1aCoil \u56fe\u7247\u52a0\u8f7d\u5e93\u9e3f\u8499\u5316\u4f7f\u7528\u5fc3\u5f97 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/119956.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CMP for OpenHarmony \u5b9e\u6218\uff1aCoil \u56fe\u7247\u52a0\u8f7d\u5e93\u9e3f\u8499\u5316\u4f7f\u7528\u5fc3\u5f97 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6846\u67b6&#xff1a;Compose Multiplatform v1.9.2-1.0.0 OpenHarmony SDK 6.0.0(20) \u5e93\u540d\u79f0&#xff1a;Coil 3.3.0&#xff08;Compose Multiplatform \u56fe\u7247\u52a0\u8f7d\u5e93&#xff09; \u9e3f\u8499\u9002\u914d\u4ed3\u5e93&#xff1a;CPF-KMP-CMP\/coil \u9002\u914d\u5206\u652f&#xff1a;main-3.3.0-OH&#xff08;\u9e3f\u8499\u5b9a\u5236\u7248&#xff09; \u7248\u672c&#xff1a;v3.3.0-1.0.0 Ma\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/119956.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-30T11:25:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030112456-6ae47e8856b52.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"21 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/119956.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/119956.html\",\"name\":\"CMP for OpenHarmony \u5b9e\u6218\uff1aCoil \u56fe\u7247\u52a0\u8f7d\u5e93\u9e3f\u8499\u5316\u4f7f\u7528\u5fc3\u5f97 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-30T11:25:01+00:00\",\"dateModified\":\"2026-10-30T11:25:01+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/119956.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/119956.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/119956.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CMP for OpenHarmony \u5b9e\u6218\uff1aCoil \u56fe\u7247\u52a0\u8f7d\u5e93\u9e3f\u8499\u5316\u4f7f\u7528\u5fc3\u5f97\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"CMP for OpenHarmony \u5b9e\u6218\uff1aCoil \u56fe\u7247\u52a0\u8f7d\u5e93\u9e3f\u8499\u5316\u4f7f\u7528\u5fc3\u5f97 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/119956.html","og_locale":"zh_CN","og_type":"article","og_title":"CMP for OpenHarmony \u5b9e\u6218\uff1aCoil \u56fe\u7247\u52a0\u8f7d\u5e93\u9e3f\u8499\u5316\u4f7f\u7528\u5fc3\u5f97 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6846\u67b6&#xff1a;Compose Multiplatform v1.9.2-1.0.0 OpenHarmony SDK 6.0.0(20) \u5e93\u540d\u79f0&#xff1a;Coil 3.3.0&#xff08;Compose Multiplatform \u56fe\u7247\u52a0\u8f7d\u5e93&#xff09; \u9e3f\u8499\u9002\u914d\u4ed3\u5e93&#xff1a;CPF-KMP-CMP\/coil \u9002\u914d\u5206\u652f&#xff1a;main-3.3.0-OH&#xff08;\u9e3f\u8499\u5b9a\u5236\u7248&#xff09; \u7248\u672c&#xff1a;v3.3.0-1.0.0 Ma","og_url":"https:\/\/www.wsisp.com\/helps\/119956.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-30T11:25:01+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030112456-6ae47e8856b52.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"21 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/119956.html","url":"https:\/\/www.wsisp.com\/helps\/119956.html","name":"CMP for OpenHarmony \u5b9e\u6218\uff1aCoil \u56fe\u7247\u52a0\u8f7d\u5e93\u9e3f\u8499\u5316\u4f7f\u7528\u5fc3\u5f97 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-30T11:25:01+00:00","dateModified":"2026-10-30T11:25:01+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/119956.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/119956.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/119956.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"CMP for OpenHarmony \u5b9e\u6218\uff1aCoil \u56fe\u7247\u52a0\u8f7d\u5e93\u9e3f\u8499\u5316\u4f7f\u7528\u5fc3\u5f97"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/119956","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=119956"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/119956\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/119952"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=119956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=119956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=119956"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=119956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}