2014-12-15 4 views
10

ग्रहण के साथ विकास करते समय, यदि मैंने पहले एक ऐप चलाया/डीबग किया है और अपना स्रोत कोड नहीं बदला है, तो यह एक ही ऐप को फिर से चलाने/डीबग करने के लिए तेज़ है।एप संकलित हर बार संकलित होता है, महत्वपूर्ण समय लेते हुए

हालांकि, एंड्रॉइड स्टूडियो और ग्रैल्डे के साथ, हर बार जब मैं ऐप चलाने/डीबग करने का प्रयास करता हूं, तो धीरे-धीरे निर्माण हमेशा चलता रहेगा, ऐप लॉन्च होने पर उस समय के अतिरिक्त 15 ~ 45 सेकंड देरी (और कभी-कभी एक 4 साल पुराने एचपी i7 लैपटॉप पर 70 सेकंड तक)।

इसलिए, सवाल यह है: क्या एंड्रॉइड स्टूडियो के ग्रेडल बिल्ड चरण को छोड़ने का कोई तरीका है, या कम से कम इसे चलाने/डीबग करने में कितना समय लगेगा?


नोट: मैं पहले से ही कॉन्फ़िगर कर दिया है gradle.properties इस प्रकार है:

org.gradle.parallel=true 
org.gradle.daemon=true 
org.gradle.configureondemand=true 

संपादित करें: मेरे Gradle निर्माण शायद सबसे परियोजनाओं से अधिक जटिल है, के रूप में यह है 7 अलग-अलग स्वाद (~ 20 तक विस्तारित होंगे) और 3 बिल्ड प्रकार, और एपीके नाम बदलने के लिए ग्रोवी कोड भी शामिल है (वर्तमान दिनांक डालें), और स्वचालित रूप से संस्करण कोड और संस्करण नाम को बढ़ाने के लिए कार्यों को सम्मिलित करें वर्तमान बिल्ड टाइप। यहाँ पूरा build.gradle (ग्राहक के नाम को छिपाने के लिए संशोधित) है:

import java.text.SimpleDateFormat 

apply plugin: 'com.android.application' 

def appendVersionNameVersionCode(applicationVariants) { 
    applicationVariants.all { variant -> 
     variant.outputs.each { output -> 
      def outputFile = output.outputFile 
      if (outputFile != null) { 
       def PREFIX = "My_APP_" 
       if (outputFile.name.endsWith('.apk') && !outputFile.name.startsWith(PREFIX)) { 
        def names = variant.baseName.split("-"); 
        def apkName = PREFIX+names[0]+"_"; 
        if(names[1].equals(android.buildTypes.debugEx.name)) { 
         apkName += 'debugEx_' 
        } else { 
         apkName += new SimpleDateFormat("YYYYMMdd").format(new Date()) 
        } 
        if(variant.name.toLowerCase().contains(android.buildTypes.release.name)) { 
         if (outputFile.name.contains('unsigned')) { 
          apkName += "-unsigned" 
         } else { 
          apkName += "_SIGNED" 
         } 
        } 
        if (!variant.outputs.zipAlign) { 
         apkName += "-unaligned" 
        } 
        apkName += ".apk" 
        println outputFile.name+" --> " + apkName 
        output.outputFile = new File(outputFile.parent, apkName) 
       } 
      } 
     } 
    } 
} 

def retrieveVersionCode(variantName) { 
    def manifestFile = file("src/$variantName/AndroidManifest.xml") 
    def pattern = Pattern.compile("versionCode=\"(\\d+)\"") 
    def manifestText = manifestFile.getText() 
    def matcher = pattern.matcher(manifestText) 
    matcher.find() 
    return Integer.parseInt(matcher.group(1)) 
} 

def retrieveVersionName(variantName) { 
    def manifestFile = file("src/$variantName/AndroidManifest.xml") 
    def pattern = Pattern.compile(Pattern.quote("versionName=\"") + "(.*?)"+ Pattern.quote("\"")) 
    def manifestText = manifestFile.getText() 
    def matcher = pattern.matcher(manifestText) 
    matcher.find() 
    return matcher.group(1) 
} 

android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.0" 

    lintOptions { 
     abortOnError false 
     absolutePaths false 
     lintConfig file("lint.xml") 
    } 

    defaultConfig { 
     applicationId "com.app.sportcam" 
     minSdkVersion 8 
     targetSdkVersion 21 
    } 

    if(project.hasProperty("app.signing") 
      && new File(project.property("app.signing")+'.gradle').exists()) { 
     apply from: project.property("app.signing")+'.gradle'; 
    } else { 
     println 'Warning, signing credential not found: ' + project.property("app.signing")+'.gradle' 
    } 

    buildTypes { 
     all { 
       buildConfigField 'String', 'IP', '"192.168.1.1"' 
       buildConfigField 'String', 'RTSP_IP', '"rtsp://"+IP+"/"' 

       //debugging 
       buildConfigField 'boolean', 'DEBUG_DETAILED', 'false' 
       buildConfigField 'boolean', 'DEBUG_UI_STATE', 'false' 
       buildConfigField 'boolean', 'INTERNAL_DEBUG', 'false' 
       buildConfigField 'boolean', 'ENABLE_VIEWSERVER', 'false' 
       buildConfigField 'boolean', 'INJECT_PTP_PROPERTIES', 'false' 

       //functional 
       buildConfigField 'boolean', 'ENABLE_TIME_LIMIT', 'false' 
       buildConfigField 'boolean', 'HIDE_ACTIONBAR_ON_LANDSCAPE', 'false' 
       buildConfigField 'boolean', 'ENABLE_VIDEO_DOWNLOAD', 'true' 
       buildConfigField 'boolean', 'ENABLE_VIDEO_DOWNLOAD_PROGRESS', 'true' 
       buildConfigField 'boolean', 'ENABLE_VIDEO_DOWNLOAD_CANCEL', 'false' 
       buildConfigField 'boolean', 'SET_TIME', 'true' 
       buildConfigField 'boolean', 'SHOULD_SET_CAMERA_MODE_WHEN_TURNING_RECORDING_OFF', 'false' 
       buildConfigField 'boolean', 'SHOULD_SET_CAMERA_MODE_ON_CONNECTION', 'false' 

      appendVersionNameVersionCode(applicationVariants) 
     } 

     release { 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 

     //for customers' testing 
     debug { 
       buildConfigField 'boolean', 'ENABLE_TIME_LIMIT', 'true' 
     } 

     //for internal testing 
     debugEx { 
       buildConfigField 'boolean', 'DEBUG_DETAILED', 'true' 
       buildConfigField 'boolean', 'INTERNAL_DEBUG', 'true' 
       buildConfigField 'boolean', 'ENABLE_VIEWSERVER', 'true' 
       buildConfigField 'boolean', 'INJECT_TEST_PROPERTIES', 'true' 

      debuggable true 
      signingConfig signingConfigs.debug 
      applicationIdSuffix ".debug" 
     } 
    } 

    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_7 
     targetCompatibility JavaVersion.VERSION_1_7 
    } 

    def time=Calendar.getInstance() 
    time.add(Calendar.MONTH, 3) 
    println 'Debug build expiry date='+time.getTime() 

    productFlavors { 
     // default BuildConfig variables 
     all { 
      buildConfigField 'long', 'TIME_LIMIT', time.getTimeInMillis()+'l' 

      buildConfigField 'boolean', 'ADD_ABOUT', 'true' 

      buildConfigField 'boolean', 'FORCE_DEVICE_CHECK', 'false' 

      buildConfigField 'boolean', 'SHOW_CUR_SELECTION_PREF', 'true' 
      buildConfigField 'boolean', 'SHOW_CUR_SELECTION_ONSCREEN', 'false' 

      buildConfigField 'boolean', 'NO_WIFI_SCREEN', 'true' 
      buildConfigField 'boolean', 'NO_STREAMING', 'false' 
      buildConfigField 'boolean', 'NO_GALLERY', 'false' 

      buildConfigField 'boolean', 'INIT_IN_START', 'true' 

      buildConfigField 'boolean', 'CUSTOM_FUNCTIONS', 'true' 

      buildConfigField 'boolean', 'ENABLE_TIMEOUT_CONTINUE', 'false' 

      buildConfigField 'boolean', 'TRANSPARENT_BOTTOM_BAR', 'false' 

      buildConfigField 'int', 'LOGO_TIMING', '1000' 
     } 

     default { 
      //mandatory 
      buildConfigField 'int', 'CUSTOMER_NAME_PREFIX', '0xFF' 

      buildConfigField 'boolean', 'ADD_ABOUT', 'false' 

      applicationId = 'com.app.default' 
      def variantName='DEFAULT' 
      versionCode retrieveVersionCode(variantName) 
      versionName retrieveVersionName(variantName) 
     } 

     Customer_1 { 
      //mandatory 
      buildConfigField 'int', 'CUSTOMER_NAME_PREFIX', '0x0B' 

      buildConfigField 'boolean', 'FORCE_DEVICE_CHECK', 'true' 

      applicationId 'com.app.c1' 
      def variantName='c1' 
      versionCode retrieveVersionCode(variantName) 
      versionName retrieveVersionName(variantName) 
     } 

     Customer_2 { 
      //mandatory 
      buildConfigField 'int', 'CUSTOMER_NAME_PREFIX', '0xFF' //TODO not final 

      buildConfigField 'boolean', 'SHOW_CUR_SELECTION_ONSCREEN', 'true' 

      applicationId 'com.app.c2' 
      def variantName='c2' 
      versionCode retrieveVersionCode(variantName) 
      versionName retrieveVersionName(variantName) 
     } 

     Customer_3 { 
      //mandatory 
      buildConfigField 'int', 'CUSTOMER_NAME_PREFIX', '0x12' 
      buildConfigField 'int', 'LOGO_TIMING', '3000' 

      applicationId = 'com.app.c3' 
      def variantName='c3' 
      versionCode retrieveVersionCode(variantName) 
      versionName retrieveVersionName(variantName) 
     } 

     Customer_4 { 
      //mandatory 
      buildConfigField 'int', 'CUSTOMER_NAME_PREFIX', '0x02' 

      applicationId = 'com.app.c4' 
      def variantName='c4' 
      versionCode retrieveVersionCode(variantName) 
      versionName retrieveVersionName(variantName) 
     } 

     Customer_5 { 
      //mandatory 
      buildConfigField 'int', 'CUSTOMER_NAME_PREFIX', '0x04' 

      applicationId = 'com.app.c5' 
      def variantName='c5' 
      versionCode retrieveVersionCode(variantName) 
      versionName retrieveVersionName(variantName) 
     } 

     Customer_6 { 
      //mandatory 
      buildConfigField 'int', 'CUSTOMER_NAME_PREFIX', '0xFF' 

      applicationId = 'com.app.c6' 
      def variantName='c6' 
      versionCode retrieveVersionCode(variantName) 
      versionName retrieveVersionName(variantName) 
     } 

     Customer_7 { 
      //mandatory 
      buildConfigField 'int', 'CUSTOMER_NAME_PREFIX', '0x14' 

      buildConfigField 'boolean', 'FORCE_DEVICE_CHECK', 'true' 

      applicationId = 'com.app.c7' 
      def variantName='c7' 
      versionCode retrieveVersionCode(variantName) 
      versionName retrieveVersionName(variantName) 
     } 
    } 

    sourceSets{ 
     main { 
      res.srcDirs = ['src/main/res'] 
     } 

     default { 
      res.srcDir 'src/_Strings_/Standard' 
      res.srcDir 'src/_Strings_/xx' 
     } 

     Customer_1 { 
      res.srcDir 'src/_Strings_/Standard' 
      res.srcDir 'src/_Strings_/xx' 
     } 

     Customer_2 { 
      res.srcDir 'src/_Strings_/Standard' 
      res.srcDir 'src/_Strings_/xx' 
     } 

     Customer_3 { 
      res.srcDir 'src/_Strings_/Standard' 
      res.srcDir 'src/_Strings_/xx' 
      res.srcDir 'src/_Strings_/yy' 
     } 

     Customer_4 { 
      res.srcDir 'src/_Strings_/Standard' 
      res.srcDir 'src/_Strings_/xx' 
     } 

     Customer_5 { 
      res.srcDir 'src/_Strings_/xx' 
      res.srcDir 'src/_Strings_/zz' 
     } 

     Customer_6 { 
      res.srcDir 'src/_Strings_/xx' 
      res.srcDir 'src/_Strings_/aa' 
     } 

     Customer_7 { 
      res.srcDir 'src/_Strings_/Standard' 
      res.srcDir 'src/_Strings_/xx' 
     } 
    } 
} 

import java.util.regex.Pattern 
def variantNameRegex = Pattern.quote("generate") + "(.*?)"+ Pattern.quote("BuildConfig") 
Pattern patternVariantName = Pattern.compile(variantNameRegex); 
tasks.whenTaskAdded { task -> 
    //TODO disables lint 
    if (task.name.startsWith("lint")) { 
     println 'Disables lint task: '+task.name 
     task.enabled = false 
    } 

    def m = patternVariantName.matcher(task.name) 
    if (m.find()) { 
     def variantName = m.group(1) 
     def isRelease=false 
     if (variantName.endsWith('Debug')) { 
      variantName = variantName.substring(0, variantName.lastIndexOf('Debug')) 
     } else if (variantName.endsWith('Release')) { 
      variantName = variantName.substring(0, variantName.lastIndexOf('Release')) 
      isRelease=true; 
     } else { 
      return 
     } 

     def taskIncVerCode="increaseVersionCode$variantName" 
     if(!project.hasProperty(taskIncVerCode)) { 
      project.task(taskIncVerCode) << { 
       def manifestFile = file("src/$variantName/AndroidManifest.xml") 
       def pattern = Pattern.compile("versionCode=\"(\\d+)\"") 
       def manifestText = manifestFile.getText() 
       def matcher = pattern.matcher(manifestText) 
       matcher.find() 
       def versionCode = Integer.parseInt(matcher.group(1)) 
       def manifestContent = matcher.replaceAll("versionCode=\"" + ++versionCode + "\"") 
       manifestFile.write(manifestContent) 
      } 
     } 
     task.dependsOn taskIncVerCode 

     if(isRelease) { 
      def taskIncVerName="increaseVersionName$variantName" 
      if(!project.hasProperty(taskIncVerName)) { 
       project.task(taskIncVerName) << { 
        def manifestFile = file("src/$variantName/AndroidManifest.xml") 
        def patternVersionNumber = Pattern.compile("versionName=\"(\\d+)\\.(\\d+)\\.(\\d+)\"") 
        def manifestText = manifestFile.getText() 
        def matcherVersionNumber = patternVersionNumber.matcher(manifestText) 
        matcherVersionNumber.find() 
        def majorVersion = Integer.parseInt(matcherVersionNumber.group(1)) 
        def minorVersion = Integer.parseInt(matcherVersionNumber.group(2)) 
        def pointVersion = Integer.parseInt(matcherVersionNumber.group(3)) 
        def mNextVersionName = majorVersion + "." + minorVersion + "." + (pointVersion + 1) 
        def manifestContent = matcherVersionNumber.replaceAll("versionName=\"" + mNextVersionName + "\"") 
        manifestFile.write(manifestContent) 
       } 
      } 
      task.dependsOn taskIncVerName 
     } 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.android.support:support-v4:21.0.0' 
    compile files('libs/eventbus.jar') 
    compile files('libs/libGoogleAnalyticsServices.jar') 
    compile files('libs/trove-3.0.3.jar') 
} 

यहाँ Gradle सांत्वना उत्पादन, किसी भी gralde/कोड संशोधनों के बिना दो बार चलाने को क्रियान्वित करने के द्वारा उत्पन्न की है:

Executing tasks: [:ptp_app_base:assembleCustomer_6DebugEx] 

Parallel execution with configuration on demand is an incubating feature. 
Debug build expiry date=Mon Mar 16 10:39:02 CST 2015 
Disables lint task: lintVitalCustomer_1Release 
Disables lint task: lintVitalCustomer_2Release 
Disables lint task: lintVitalDefaultRelease 
Disables lint task: lintVitalCustomer_3Release 
Disables lint task: lintVitalCustomer_4Release 
Disables lint task: lintVitalCustomer_5Release 
Disables lint task: lintVitalCustomer_6Release 
Disables lint task: lintVitalCustomer_7Release 
Disables lint task: lint 
Disables lint task: lintCustomer_1DebugEx 
Disables lint task: lintCustomer_1Debug 
Disables lint task: lintCustomer_1Release 
Disables lint task: lintCustomer_2DebugEx 
Disables lint task: lintCustomer_2Debug 
Disables lint task: lintCustomer_2Release 
Disables lint task: lintDefaultDebugEx 
Disables lint task: lintDefaultDebug 
Disables lint task: lintDefaultRelease 
Disables lint task: lintCustomer_3DebugEx 
Disables lint task: lintCustomer_3Debug 
Disables lint task: lintCustomer_3Release 
Disables lint task: lintCustomer_4DebugEx 
Disables lint task: lintCustomer_4Debug 
Disables lint task: lintCustomer_4Release 
Disables lint task: lintCustomer_5DebugEx 
Disables lint task: lintCustomer_5Debug 
Disables lint task: lintCustomer_5Release 
Disables lint task: lintCustomer_6DebugEx 
Disables lint task: lintCustomer_6Debug 
Disables lint task: lintCustomer_6Release 
Disables lint task: lintCustomer_7DebugEx 
Disables lint task: lintCustomer_7Debug 
Disables lint task: lintCustomer_7Release 
ptp_app_base-Customer_1-debugEx.apk --> MY_APP_Customer_1_debugEx_.apk 
ptp_app_base-Customer_1-debug.apk --> MY_APP_Customer_1_20141216.apk 
ptp_app_base-Customer_1-release.apk --> MY_APP_Customer_1_20141216_SIGNED.apk 
ptp_app_base-Customer_2-debugEx.apk --> MY_APP_Customer_2_debugEx_.apk 
ptp_app_base-Customer_2-debug.apk --> MY_APP_Customer_2_20141216.apk 
ptp_app_base-Customer_2-release.apk --> MY_APP_Customer_2_20141216_SIGNED.apk 
ptp_app_base-default-debugEx.apk --> MY_APP_default_debugEx_.apk 
ptp_app_base-default-debug.apk --> MY_APP_default_20141216.apk 
ptp_app_base-default-release.apk --> MY_APP_default_20141216_SIGNED.apk 
ptp_app_base-Customer_3-debugEx.apk --> MY_APP_Customer_3_debugEx_.apk 
ptp_app_base-Customer_3-debug.apk --> MY_APP_Customer_3_20141216.apk 
ptp_app_base-Customer_3-release.apk --> MY_APP_Customer_3_20141216_SIGNED.apk 
ptp_app_base-Customer_4-debugEx.apk --> MY_APP_Customer_4_debugEx_.apk 
ptp_app_base-Customer_4-debug.apk --> MY_APP_Customer_4_20141216.apk 
ptp_app_base-Customer_4-release.apk --> MY_APP_Customer_4_20141216_SIGNED.apk 
ptp_app_base-i3-debugEx.apk --> MY_APP_i3_debugEx_.apk 
ptp_app_base-i3-debug.apk --> MY_APP_i3_20141216.apk 
ptp_app_base-i3-release.apk --> MY_APP_i3_20141216_SIGNED.apk 
ptp_app_base-i5-debugEx.apk --> MY_APP_i5_debugEx_.apk 
ptp_app_base-i5-debug.apk --> MY_APP_i5_20141216.apk 
ptp_app_base-i5-release.apk --> MY_APP_i5_20141216_SIGNED.apk 
ptp_app_base-Customer_7-debugEx.apk --> MY_APP_Customer_7_debugEx_.apk 
ptp_app_base-Customer_7-debug.apk --> MY_APP_Customer_7_20141216.apk 
ptp_app_base-Customer_7-release.apk --> MY_APP_Customer_7_20141216_SIGNED.apk 
:ptp_app_base:preBuild 
:ptp_app_base:compileCustomer_6DebugExNdk UP-TO-DATE 
:ptp_app_base:preCustomer_6DebugExBuild 
:ptp_app_base:checkCustomer_6DebugExManifest 
:ptp_app_base:preCustomer_4DebugBuild 
:ptp_app_base:preCustomer_4DebugExBuild 
:ptp_app_base:preCustomer_4ReleaseBuild 
:ptp_app_base:preCustomer_5DebugBuild 
:ptp_app_base:preCustomer_5DebugExBuild 
:ptp_app_base:preCustomer_5ReleaseBuild 
:ptp_app_base:preCustomer_6DebugBuild 
:ptp_app_base:preCustomer_6ReleaseBuild 
:ptp_app_base:preDefaultDebugBuild 
:ptp_app_base:preDefaultDebugExBuild 
:ptp_app_base:preDefaultReleaseBuild 
:ptp_app_base:preCustomer_3DebugBuild 
:ptp_app_base:preCustomer_3DebugExBuild 
:ptp_app_base:preCustomer_3ReleaseBuild 
:ptp_app_base:preCustomer_7DebugBuild 
:ptp_app_base:preCustomer_7DebugExBuild 
:ptp_app_base:preCustomer_7ReleaseBuild 
:ptp_app_base:preCustomer_1DebugBuild 
:ptp_app_base:preCustomer_1DebugExBuild 
:ptp_app_base:preCustomer_1ReleaseBuild 
:ptp_app_base:preCustomer_2DebugBuild 
:ptp_app_base:preCustomer_2DebugExBuild 
:ptp_app_base:preCustomer_2ReleaseBuild 
:ptp_app_base:prepareComAndroidSupportSupportV42100Library UP-TO-DATE 
:ptp_app_base:prepareCustomer_6DebugExDependencies 
:ptp_app_base:compileCustomer_6DebugExAidl UP-TO-DATE 
:ptp_app_base:compileCustomer_6DebugExRenderscript UP-TO-DATE 
:ptp_app_base:generateCustomer_6DebugExBuildConfig 
:ptp_app_base:generateCustomer_6DebugExAssets UP-TO-DATE 
:ptp_app_base:mergeCustomer_6DebugExAssets UP-TO-DATE 
:ptp_app_base:generateCustomer_6DebugExResValues UP-TO-DATE 
:ptp_app_base:generateCustomer_6DebugExResources UP-TO-DATE 
:ptp_app_base:mergeCustomer_6DebugExResources UP-TO-DATE 
:ptp_app_base:processCustomer_6DebugExManifest UP-TO-DATE 
:ptp_app_base:processCustomer_6DebugExResources UP-TO-DATE 
:ptp_app_base:generateCustomer_6DebugExSources 
:ptp_app_base:compileCustomer_6DebugExJava 
Note: Some input files use or override a deprecated API. 
Note: Recompile with -Xlint:deprecation for details. 
Note: Some input files use unchecked or unsafe operations. 
Note: Recompile with -Xlint:unchecked for details. 

:ptp_app_base:preDexCustomer_6DebugEx UP-TO-DATE 
:ptp_app_base:dexCustomer_6DebugEx 
:ptp_app_base:processCustomer_6DebugExJavaRes UP-TO-DATE 
:ptp_app_base:validateDebugSigning 
:ptp_app_base:packageCustomer_6DebugEx 
:ptp_app_base:zipalignCustomer_6DebugEx 
:ptp_app_base:assembleCustomer_6DebugEx 

BUILD SUCCESSFUL 

Total time: 30.303 secs 

वर्तमान बिल्ड स्क्रिप्ट शायद सबसे अधिक प्रदर्शनकारी नहीं है, इसलिए पुनर्निर्माण या गति को बढ़ाने के तरीके पर दोनों सुझावों की सराहना की जाएगी।


संपादित करें 2: मैंने देखा Gradle निर्माण समय की सबसे पर खर्च किया जाता है:

  1. संकलन [एप्लिकेशन] जावा
  2. डेक्स [एप्लिकेशन]
  3. पैकेज [एप्लिकेशन]

इस कदम के बावजूद ये कदम चलने लगते हैं कि अंतिम निर्माण के बाद से कुछ भी नहीं बदला है।


संपादित करें 3: मूल शीर्षक बेहतर मुद्दा और उपाय के लक्षण प्रतिबिंबित करने के लिए बदल गया "कैसे छोड़ Gradle एंड्रॉयड स्टूडियो के साथ निर्माण जब चल रहा है/डिबगिंग", था।

मैं मिलीसेकेंड में वर्तमान समय है, जो कारण होता है, जिसके परिणामस्वरूप BuildConfig.java हर बार Gradle चलाता अलग होने की, पूरे संकलन/Dexing/पैकेजिंग के कारण होने के लिए एक BuildConfig क्षेत्र सेट करें:

+2

वर्तमान में, यह एक ज्ञात मुद्दा है कि हर बार जब आप ऐप चलाते हैं तो ग्रैडल फिर से चलाया जाएगा। हालांकि, इसे सभी कार्यों के लिए यूपी से DATE को दिखाना चाहिए और कुछ भी नहीं बनाना चाहिए, और इसे आपके डिवाइस पर एपीके को पुनर्स्थापित नहीं करना चाहिए। यदि यह है, तो कुछ मजाकिया चल रहा है। ग्रैडल का फिर से चलना काफी तेज़ होना चाहिए (सेकंड की कम एकल अंक संख्या) क्योंकि इसमें कुछ भी नहीं होना चाहिए; 15-45 सेकंड बहुत असामान्य है। क्या आप ग्रैडल कंसोल आउटपुट शामिल कर सकते हैं? और अपनी बिल्ड स्क्रिप्ट फाइलें शामिल करें? –

+0

आप किस निर्माण विन्यास का उपयोग कर रहे हैं? क्या आप इसका एसएस पोस्ट कर सकते हैं – browep

+0

@ स्कॉटबार्ट ऐसा लगता है कि मेरा ग्रेडल बिल्ड पूरे संकलन, डीईएक्स, पैकेज प्रक्रिया, किसी भी विचार को छोड़ने के तरीके के माध्यम से जाएगा? धन्यवाद – Kai

उत्तर

13

कारण मेरी ओर से मूर्खता है चलाने के लिए चरण।

संपादित करें:

मेरे लिए समस्या समान स्क्रिप्ट पर कार्य यह करने के लिए की वजह से किया गया था:

productFlavors { 
    all { 
     buildConfigField 'long', 'TIME_LIMIT', System.currentTimeMillis() + 'l' 
    } 
    ... 
} 

के बाद से System.currentTimeMillis() अलग हर बार हो सकता है, यह हर बार Gradle चलाता है का मतलब है यह स्रोत कोड बदल गया है, इसलिए कार्यों के एक झुकाव ट्रिगर। स्क्रिप्ट को बदलकर हल किया जाता है:

def time = Calendar.getInstance() 
time.set(Calendar.HOUR, 1); 
time.set(Calendar.MINUTE, 1); 
time.set(Calendar.SECOND, 1); 
time.set(Calendar.MILLISECOND, 1); 
productFlavors { 
    // default BuildConfig variables 
    all { 
     buildConfigField 'long', 'TIME_LIMIT', time.getTimeInMillis() + 'l' 
    } 
    ... 
} 

उपरोक्त स्क्रिप्ट का अर्थ है कि उसी दिन चलने पर सटीक समय का उत्पादन होता है। इसलिए यदि कुछ और नहीं बदला गया था तो पिछली जेनरेट की गई एपीके का पुन: उपयोग करने के लिए पुन: उपयोग नहीं किया जाएगा।

+0

भागने के लिए आप जो पाठ जोड़ चुके हैं –

+0

विस्तृत उत्तर देखें – Kai

+0

वास्तव में बहुत बढ़िया धन्यवाद –

संबंधित मुद्दे