{"id":2677,"date":"2020-01-16T11:10:53","date_gmt":"2020-01-16T03:10:53","guid":{"rendered":"http:\/\/learn-house.idv.tw\/?p=2677"},"modified":"2020-01-17T14:46:28","modified_gmt":"2020-01-17T06:46:28","slug":"aosp%e5%8d%87%e7%b4%9aandroid-support%e5%88%b0androidx","status":"publish","type":"post","link":"https:\/\/learn-house.idv.tw\/?p=2677","title":{"rendered":"[Android]AOSP\u5347\u7d1aandroid.support\u5230androidx"},"content":{"rendered":"<p>Android 9\u4e4b\u5f8c\u5df2\u7d93\u555f\u52d5androidx\u7684library\uff0c\u4e5f\u5c31\u662f\u5c07\u4f86support library\u5c07\u4e0d\u518dmaintain\u4e86<\/p>\n<p>\u7531\u65bcgoogle\u5b98\u7db2\u53ea\u63d0\u4f9bAndroid studio\u7684\u5347\u7d1a\u6b65\u9a5f\uff0c\u5c0d\u65bc\u958b\u767cAOSP\u5bebAndroid.mk\u7684\u537b\u90fd\u6c92\u6709\u8457\u58a8<\/p>\n<p>\u53c3\u8003\u4e86google\u5728AOSP\u4e0a\u7684\u5176\u5b83APP\uff0c\u6574\u7406\u6e2c\u8a66\u5f8c\u53ef\u4f9d\u4e0b\u5217\u6b65\u9a5f\u4fee\u6539\u4f86\u9032\u884c\u5347\u7d1a\u5230androidx<\/p>\n<p><!--more--><br \/>\n<span style=\"color: #993300;\"><strong>1. \u4fee\u6539Android.mk, \u8a3b1<\/strong><\/span><br \/>\n\u65b0\u589e<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/\u4f7f\u7528androidx lib \r\nLOCAL_USE_AAPT2 := true \r\n\r\n\/\/APP\u4f7f\u7528\u4e86\u54ea\u500blib\u5c31\u7f6e\u63db\u6210\u76f8\u5c0d\u61c9\u7684 \r\nLOCAL_STATIC_JAVA_LIBRARIES := \\ \r\n       androidx.appcompat_appcompat \\ (\u4fee\u6539\u524d:android-support-v7-appcompat) \r\n       androidx.cardview_cardview \\ (\u4fee\u6539\u524d:android-support-v7-cardview)\r\n<\/pre>\n<p><span style=\"color: #993300;\"><strong>2. \u66ff\u63db\u6240\u6709\u7684java\u6a94\u7684import, \u8a3b2<\/strong><\/span><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\"> import androidx.appcompat.app.AlertDialog; \/\/(\u4fee\u6539\u524d: import android.support.v7.app.AlertDialog) <\/pre>\n<p><span style=\"color: #993300;\"><strong>3. \u82e5\u9047\u5230thrid-party\u7684jar\u6a94\uff0c\u4e5f\u9808\u540c\u6b65\u66f4\u65b0<\/strong><\/span><\/p>\n<p><span style=\"color: #993300;\"><strong>4.\u82e5\u9047\u5230\u4e0b\u5217\u932f\u8aa4\u8a0a\u606f\u9700\u4fee\u6539proguard.cfg<\/strong><\/span><\/p>\n<blockquote><p>Warning: android.support.v4.media.SessionToken2ImplLegacy: can't find referenced method 'android.support.v4.media.session.MediaSessionCompat$Token fromBundle(android.os.Bundle)' in program class android.support.v4.media.session.MediaSessionCompat$Token<br \/>\nWarning: there were 6 unresolved references to program class members.<br \/>\nYour input classes appear to be inconsistent.<br \/>\nYou may need to recompile the code.<br \/>\n(http:\/\/proguard.sourceforge.net\/manual\/troubleshooting.html#unresolvedprogramclassmember)<br \/>\nError: Please correct the above warnings first.<\/p><\/blockquote>\n<p>\u5728\u6700\u4e0b\u65b9\u52a0\u5165<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n# The support library contains references to newer platform versions.\r\n# Don't warn about those in case this app is linking against an older\r\n# platform version.  We know about them, and they are safe.\r\n-dontwarn android.support.**\r\n<\/pre>\n<p>\u8a3b1: \u53c3\u8003\u5b98\u7db2<a href=\"https:\/\/developer.android.com\/jetpack\/androidx\/migrate\/artifact-mappings\">Artifact Mappings<\/a>\u7f6e\u63db\uff0c\u4f46\u9808\u6ce8\u610f\u5b98\u7db2\u5217\u7684\u662fstudio\u7684\u4f5c\u6cd5\uff0c\u9019\u88e1\u300e:\u300f\u9808\u6539\u6210\u300e_\u300f<br \/>\n\u8a3b2: \u53c3\u8003\u5b98\u7db2<a href=\"https:\/\/developer.android.com\/jetpack\/androidx\/migrate\/class-mappings\">Class Mappings<\/a>\u4fee\u6539\u6240\u6709\u7684import<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android 9\u4e4b\u5f8c\u5df2\u7d93\u555f\u52d5androidx\u7684library\uff0c\u4e5f\u5c31\u662f\u5c07\u4f86support library\u5c07\u4e0d\u518d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-2677","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/2677"}],"collection":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2677"}],"version-history":[{"count":0,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/2677\/revisions"}],"wp:attachment":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}