Details

      Description

      Summary:
      Titanium currently support "Java 7" language features.

      In Titanium 9.0.0, we would like to add "Java 8" language features for the core SDK and all modules. This is needed since some 3rd party Android libraries use the Java 8 language, but we're currently unable to compile them into a module or via hyperloop.

      Limitations:
      Android has limited support for Java 8 language features which Google documents below. Note that older Android OS versions support less Java 8 features.
      https://developer.android.com/studio/write/java8-support#supported_features

      Recommended Solution:
      We don't support Java 8 because Titanium is currently limited to using the "dex" command line tool in the Android SDK which only supports up to Java 7. Google's "d8" command line tool supports Java 8. If we update our Titanium build system to use gradle, then we can easily add support for this.

      Support can be added via the following "build.gradle" settings...

      android {
      	compileOptions {
      		sourceCompatibility JavaVersion.VERSION_1_8
      		targetCompatibility JavaVersion.VERSION_1_8
      	}
      	// When we add Kotlin support in the future,
      	// then we must do the following as well.
      	kotlinOptions {
      		jvmTarget = "1.8"
      	}
      }
      

      Testing:
      We should add a Java 8 feature to our core Titanium code to prove that Java 8 compilation works for both the SDK and an app build. In our TiUIView.java code, I recommend that we change the following code...

      protected void setOnClickListener(View view)
      {
      	view.setOnClickListener(new OnClickListener() {
      		public void onClick(View view)
      		{
      			fireEvent(TiC.EVENT_CLICK, dictFromEvent(lastUpEvent));
      		}
      	});
      }
      

      ...to use a Java 8 lambda as follows...

      protected void setOnClickListener(View view)
      {
      	view.setOnClickListener((clickedView) -> {
      		fireEvent(TiC.EVENT_CLICK, dictFromEvent(lastUpEvent));
      	});
      }
      

      We can then test the above via a Titanium Ti.UI.Button object's "click" event.

      var window = Ti.UI.createWindow();
      var button = Ti.UI.createButton({ title: "Show Alert" });
      button.addEventListener("click", function() {
      	alert("Button clicked!");
      });
      window.add(button);
      window.open();
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jquick Joshua Quick
                Reporter:
                jquick Joshua Quick
              • Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Source Code