2016-10-10 6 views
1

私は一般的なグループのヘルプを依頼しましたが、ほとんどの人がそれをうまく利用できませんでした。 私の単純なアプリのばかばかしい問題を抱えています。私は@markoskoのnativescriptフィルタを使って、アプリを17.2MBから14MBに減らしました。さらに、nativescript-snapshotはリリース版でも17MBを助けることができませんでした。ABI SplitがNativeScriptで失敗しました2.3.0

私はnativesciptドキュメントでABI分割サンプルを使用してみましたが、私が気づいたことは、それを分割しようとしているということですが、私は私のapp.glade

にこの思い付いたので空き地には、すべてのAPKに同じ名前を使用しています
def tnsBuildMultipleApks=true; 

android { 
    defaultConfig { 
     generatedDensities = [] 
     applicationId = "com.maliyo.oneclick" 
     versionCode Integer.parseInt("" + "1" + "0") 
    } 
    aaptOptions { 
     additionalParameters "--no-version-vectors" 
    } 
    if (Boolean.valueOf(tnsBuildMultipleApks)) { 
     splits { 
      abi { 
       enable true 
       reset() 
       include 'armeabi', 'armeabi-v7a', 'x86', 'mips' 
       universalApk true 
      } 
     } 
    } 
} 

def getDate() { 
    def date = new Date() 
    def formattedDate = date.format('yyyyMMdd') 
    return formattedDate 
} 

// map for the version code that gives each ABI a value 
ext.versionCodes = [ 
    'F0F1F2X86Debug':1, 'F0F1F2ArmeabiDebug':2, 'F0F1F2Armeabi-v7aDebug':3, 'F0F1F2MipsDebug':4, 
    'F0F1F2X86Release':1, 'F0F1F2ArmeabiRelease':2, 'F0F1F2Armeabi-v7aRelease':3, 'F0F1F2MipsRelease':4 
    ] 

// For each APK output variant, override versionCode with a combination of 
// ABI APK value * 100 + defaultConfig.versionCode 
android.applicationVariants.all { variant -> 
    // assign different version code for each output 
    variant.outputs.each { output -> 
     if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) { 
      println("******************************************************") 
      println(output); 
      println(output.getVariantOutputData().getFullName()) 

      if (Boolean.valueOf(tnsBuildMultipleApks)) { 
       def file = output.outputFile 
       // version at the end of each built apk 
       //output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + android.defaultConfig.versionName + "-" + getDate() + ".apk")) 
       output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + output.getVariantOutputData().getFullName() + "-" + getDate() + ".apk")) 
       output.versionCodeOverride = 
        //(assd++) * 100 
        project.ext.versionCodes.get(output.getVariantOutputData().getFullName(), 0) * 100 
        + android.defaultConfig.versionCode 
      } 
     } 
    } 
} 
/**/ 

細かいところが分かりますが、出力時にファイル名をハッキングしたため、adbはデバイス名やエミュレータ名に合わせてapkを見つけられませんでした。おそらくapk not foundと言っています。

私は、それが正常にインストールアプリが、それはそんなにあなたの貢献のためのplamen-ペトコフ感謝@metadata/treeNodeStream.dat could not be loaded

UPDATE

を言っスプラッシュスクリーン後にクラッシュし、手動でUSBを介してデバイスに適切なAPKを送信しようとしましたあなたがabiフィルタを変更した後にビルドするときにうまく動作することに同意します。しかし、これで私のapp.gradleで、私は複数のapkをうまく構築し、テストしてOKでした。

と同じですが、tnsはappname-debug.apkまたはappname-release.apkをadbにプッシュするようなものです。私はtnsBuildMultipleApksと、この分割をオフに切り替えることができ、イムはまだテストしたときに多分私はそれをオフにしてtns run androidを使用して、私は最終ビルドをしたいとき、それはtns build android --release ....

// Add your native dependencies here: 

// Uncomment to add recyclerview-v7 dependency 
//dependencies { 
// compile 'com.android.support:recyclerview-v7:+' 
//} 
import groovy.json.JsonSlurper //used to parse package.json 

def tnsBuildMultipleApks=true; 
String content = new File("$projectDir/../../app/package.json").getText("UTF-8") 
def jsonSlurper = new JsonSlurper() 
def appPackageJson = jsonSlurper.parseText(content) 

android { 
    defaultConfig { 
     generatedDensities = [] 
     applicationId = appPackageJson.nativescript.id 
     versionCode = appPackageJson.version_code ?: 1 
    } 

    aaptOptions { 
     additionalParameters "--no-version-vectors" 
    } 
    if (Boolean.valueOf(tnsBuildMultipleApks)) { 
     splits { 
      abi { 
       enable true 
       reset() 
       include 'x86', 'armeabi-v7a', 'arm64-v8a' 
       universalApk true 
      } 
     } 
    } 
} 

// map for the version code that gives each ABI a value 
ext.versionCodes = [ 
    'x86':1, 'armeabi-v7a':2, 'arm64-v8a':3 
] 

// For each APK output variant, override versionCode with a combination of 
// ABI APK value * 100 + android.defaultConfig.versionCode 
// getAbiFilter() not working for me so I extracted it from getFullname() 
if (Boolean.valueOf(tnsBuildMultipleApks)) { 
    android.applicationVariants.all { variant -> 
     println(appPackageJson) 
     println(android.defaultConfig.versionCode) 
     println(android.defaultConfig.applicationId) 

     def name 
     def flavorNamesConcat = "" 

     variant.productFlavors.each() { flavor -> 
      flavorNamesConcat += flavor.name 
     } 
     flavorNamesConcat = flavorNamesConcat.toLowerCase() 
     println(flavorNamesConcat) 

     variant.outputs.each { output -> 
      if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) { 
       //You may look for this path in your console to see what the values are 
       println("******************************************************") 
       println(output); println(output.getVariantOutputData().getFullName()) 

       def abiName = output.getVariantOutputData().getFullName().toLowerCase().replace(flavorNamesConcat, "").replace(project.ext.selectedBuildType, "") 
       println(abiName) 


       def file = output.outputFile 
       output.versionCodeOverride = 
        project.ext.versionCodes.get(abiName, 0) * 100 
        + android.defaultConfig.versionCode 

       def apkDirectory = output.packageApplication.outputFile.parentFile 
       def apkNamePrefix = output.outputFile.name.replace(".apk", "-" + abiName) 

       if (output.zipAlign) { 
        name = apkNamePrefix + ".apk" 
        output.outputFile = new File(apkDirectory, name); 
       } 

       name = apkNamePrefix + "-unaligned.apk" 
       output.packageApplication.outputFile = new File(apkDirectory, name); 
      } 
     } 
    } 
} 

答えて

1

これは今私にとってはうまくいくので、apksとtns run androidの両方が生成されます。

// Add your native dependencies here: 

// Uncomment to add recyclerview-v7 dependency 
//dependencies { 
// compile 'com.android.support:recyclerview-v7:+' 
//} 
import groovy.json.JsonSlurper //used to parse package.json 

def tnsBuildMultipleApks=true; 
String content = new File("$projectDir/../../app/package.json").getText("UTF-8") 
def jsonSlurper = new JsonSlurper() 
def appPackageJson = jsonSlurper.parseText(content) 

android { 
    defaultConfig { 
     generatedDensities = [] 
     applicationId = appPackageJson.nativescript.id 
     versionCode = appPackageJson.version_code ?: 1 
    } 

    aaptOptions { 
     additionalParameters "--no-version-vectors" 
    } 
    if (Boolean.valueOf(tnsBuildMultipleApks)) { 
     splits { 
      abi { 
       enable true 
       reset() 
       include 'x86', 'armeabi-v7a', 'arm64-v8a' 
       universalApk true 
      } 
     } 
    } 
} 

// map for the version code that gives each ABI a value 
ext.versionCodes = [ 
    'x86':1, 'armeabi-v7a':2, 'arm64-v8a':3 
] 

// For each APK output variant, override versionCode with a combination of 
// ABI APK value * 100 + android.defaultConfig.versionCode 
// getAbiFilter() not working for me so I extracted it from getFullname() 
if (Boolean.valueOf(tnsBuildMultipleApks)) { 
    android.applicationVariants.all { variant -> 
     println(appPackageJson) 
     println(android.defaultConfig.versionCode) 
     println(android.defaultConfig.applicationId) 

     def name 
     def flavorNamesConcat = "" 

     variant.productFlavors.each() { flavor -> 
      flavorNamesConcat += flavor.name 
     } 
     flavorNamesConcat = flavorNamesConcat.toLowerCase() 
     println(flavorNamesConcat) 

     variant.outputs.each { output -> 
      if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) { 
       //You may look for this path in your console to see what the values are 
       println("******************************************************") 
       println(output); println(output.getVariantOutputData().getFullName()) 

       def abiName = output.getVariantOutputData().getFullName().toLowerCase().replace(flavorNamesConcat, "").replace(project.ext.selectedBuildType, "") 
       println(abiName) 


       def file = output.outputFile 
       def versionCode = project.ext.versionCodes.get(abiName, 0); 
       output.versionCodeOverride = 
        project.ext.versionCodes.get(abiName, 0) * 100 
        + android.defaultConfig.versionCode 

       def apkDirectory = output.packageApplication.outputFile.parentFile 
       println(output.outputFile.name) 
       def apkNamePrefix = "" 
       if(versionCode){ 
        apkNamePrefix = output.outputFile.name.replace(".apk", "-" + abiName) 
       } 
       else { 
        apkNamePrefix = output.outputFile.name.replace(".apk", "") 
       } 

       if (output.zipAlign) { 
        name = apkNamePrefix + ".apk" 
        output.outputFile = new File(apkDirectory, name); 
       } 

       name = apkNamePrefix + "-unaligned.apk" 
       output.packageApplication.outputFile = new File(apkDirectory, name); 
      } 
     } 
    } 
} 
3
で正常に動作して、それが再び1にそれを回すことができます

ABI分割は、一度に1つずつ使用すると便利です。ここでは例です:それはABIに言及した唯一のアーキテクチャです上記の構成を分割しているため

android { 
... 
    splits { 
     abi { 
      enable true 
      reset() 
      include 'armeabi-v7a' 
     } 
    } 
... 
} 

結果の.apkファイルは、armeabi-v7aデバイスのために必要なライブラリが含まれています。使用可能なABIはdocumentationで指摘されている 'arm64-v8a'、 'armeabi-v7a'、 'x86'です。したがって、 'armeabi'または 'mips'アーキテクチャは使用できません。

さらに、「universalApk true」という行は必要ありません。これは、分割を無視して、提供されているすべてのアーキテクチャを含む1つの.apkファイルを作成し、その逆をしたいからです。

thisの問題の進捗状況を確認すると、.apkのサイズがさらに縮小されるため、この問題が発生する可能性があります。

希望すると便利です。

関連する問題