Android Studio 의 코드 다 중 채널 포장 실현 방법

한 세트의 코드 가 다음 과 같은 효과 에 도달 합 니 다:
  • 서로 다른 applicationId 를 포장 하여 같은 핸드폰 에 동시에 설치 할 수 있다
  • 서로 다른 로고,app 이름,
  • 서로 다른 제3자 SDK 접속 설정(예 를 들 어 위 챗 공유 appid,레이저 푸 시 appkey)
  • debug 와 release 설정 을 구분 할 수 있 습 니 다
  • 사용 되 는 기능:produtFlavor 와 buildTypes
  • 원리:우선 순위 buildTypes 가 produtFlavor 보다 큽 니 다.
    예:코드 한 세트 는 두 은행 에 apk 를 포장 합 니 다.
    1.build.gradle 을 수정 합 니 다.buildTypes 는 기본 debug 와 release 두 가지 설정 을 유지 하면 됩 니 다.android 노드 에 두 개의 produtFlavor 를 추가 합 니 다.
    
    flavorDimensions 'bank'
    productFlavors {
     icbc {
     dimension = 'bank'
     applicationId='com.icbc.mobilebank
     manifestPlaceholders = [bankName: '    ']
     }
     ccb {
     dimension = 'bank'
     applicationId = 'com.cbc. mobilebank
     manifestPlaceholders = [bankName: '    ']
     }
    }
    2.src\main\\AndroidManifest.xml 을 수정 하고"${bankName}"와${applicationId}를 사용 하여 해당 위 치 를 교체 합 니 다.
    2.1 app 이름,android:label="${bankName}"을 설정 합 니 다.tools:replace 에 android:label 을 추가 해 야 합 니 다.(App logoandroid:icon 도 이 방법 으로 구분 할 수 있 지만 뒤의 방법 을 추천 합 니 다)
    
    <application
    android:name="com.dhcc.app.application.MyApplication"
    android:allowClearUserData="true"
    android:icon="@drawable/logo"
    android:label="${bankName}"
    android:largeHeap="true"
    android:networkSecurityConfig="@xml/network_security_config"
    tools:replace="android:name,android:label"
    tools:targetApi="n">
    2.2 모든 android:authorities 를 설정 합 니 다.예 를 들 어
    
    <provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}. FileProvider "
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
    android:name="android.support.FILE_PROVIDER_PATHS"
    android:resource="@xml/file_paths" />
    </provider>
     
    <provider android:name="cn.jpush.android.service.DataProvider"
    android:process=":pushcore"
    android:authorities="${applicationId}.DataProvider" android:exported="false" />
    2.3 제3자 sdk 를 인용 했다.예 를 들 어 극광 푸 시 는 수정 이 필요 하 다.
    
    <permission android:name="${applicationId}.permission.JPUSH_MESSAGE"
    android:protectionLevel="signature" />
    <permission android:name="${applicationId}.permission.MIPUSH_RECEIVE"
    android:protectionLevel="signature" />
    3.src\main 동급 디 렉 터 리 에 세 개의 폴 더"icbc","icbcRelease,"release"를 추가 합 니 다.icbcRelease 컴 파일 을 선택 하면 컴 파일 러 는'icbcRelease>release>icbc>main'과 같은 우선 순위 로 같은 이름 의 파일 을 컴 파일 합 니 다.
    4.위의 우선 순위 에 따라 그림 자원 을 설정 합 니 다.main\res\drawable\logo.png 파일 등급 을 참조 하여 폴 더 에 사용자 정의 app 로 고 를 추가 합 니 다.만약 icbc 가 debug 와 release 에 같은 로 고 를 사용한다 면 icbc 폴 더 에 만 추가 하면 됩 니 다.
    5.문자열 xml 자원 을 설정 합 니 다.
    5.1 src\main\res\values\configs.xml 를 새로 만 들 고 은행 마다 다른 인 자 를 배치 합 니 다.configs.xml 파일 을 추가 하지 않 고 strings.xml 에 직접 추가 할 수도 있 습 니 다.
    
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <string name="WXAPPId">XXXXXXXXXXXXXXX</string>
    <string name="JPUSH_APPKEY">XXXXXXXXXXXXXXXXXX</string>
    </resources>
    5.2 실제 상황 에 따라'icbc','icbcRelease','release'에 대응 하 는 configs.xml 를 추가 합 니 다.JPUSH 만 증가앱 키,그러면 WXAPPId 는 main 값 을 사용 합 니 다.
    5.3 AndroidManifest.xml 등 xml 파일 에서'@string/JPUSH애플 리 케 이"사용
    5.4 activity 코드 에서 사용 하 는 방법:"this.getString(R.string.resourcename);"또는"this.getString(R.string.resourcename);"
    5.5 다른 자바 파일 에서 사용 하 는 방법(Context 또는 pplication 이 있어 야 함):"context.getString(R.string.resourcename);"또는"application.getString(R.string.resourcename);"
    다른 제안:
    1.다른 모든 파일 은 자바 를 포함 하여 이러한 우선 순위 로 서로 다른 가방 으로 서로 다른 논리 적 효 과 를 낼 수 있 습 니 다.
    2.Logo,configs.xml 의 매개 변 수 는 manifestPlaceholders 에서 각각 다른 flavor 의 다른 효 과 를 사용자 정의 할 수 있 지만'icbc','icbcRelease','icbcDebug','release','debug'와 같은 다양한 조합 이 서로 다른 효 과 를 낼 수 없습니다.동시에 자바 코드 에서 manifestPlaceholders 의 값 을 가 져 오 는 것 이 configs.xml 의 값 을 가 져 오 는 것 보다 귀 찮 습 니 다.그래서 각자 다른 폴 더 를 만 드 는 것 을 추천 합 니 다.나중에 한 은행 의 설정 을 삭제 하 는 것 도 쉽 습 니 다.
    총결산
    안 드 로 이 드 스튜디오 의 코드 다 중 채널 포장 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 안 드 로 이 드 스튜디오 다 중 채널 포장 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 저 희 를 많이 사랑 해 주세요!

    좋은 웹페이지 즐겨찾기