Android Extension breaks the build!

For the first time I am writing an Android Extension and following this tutorial

However running the project breaks the build with following message.

FAILURE: Build failed with an exception.

 What went wrong:
A problem occurred configuring project ':app'.
> A problem occurred configuring project ':deps:setbrightness'.
   > Could not resolve all dependencies for configuration ':deps:setbrightness:classpath'.
      > Could not find com.android.tools.build:gradle:null.
        Searched in the following locations:
            http://repo1.maven.org/maven2/com/android/tools/build/gradle/null/gradle-null.pom
            http://repo1.maven.org/maven2/com/android/tools/build/gradle/null/gradle-null.jar
        Required by:
            bin.deps:setbrightness:unspecified

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Any help would be a nice help.
thanks.

Oh, yeah. I noticed that a couple months back, but I guess we never did anything about it.

I should go follow up on that. In the meantime, all you need to do is open up SetBrightness/dependencies/android/build.gradle, find the line that looks like this:

classpath 'com.android.tools.build:gradle:null'

…and change it to this:

classpath 'com.android.tools.build:gradle:::ANDROID_GRADLE_PLUGIN::'

thanks @player_03 for the response.

The trick is not working. just tried it and got the exact same error message!

Can you post what you see in Export/android/debug/bin/deps/SetBrightness/build.gradle?

thanks @player_03. Here is the build.gradle

 buildscript {
	repositories {
		maven {
			url "http://repo1.maven.org/maven2/"
		}
	}
	
	dependencies {
		classpath 'com.android.tools.build:gradle2.1.0'
	}
}

apply plugin: 'com.android.library'

android {
	compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
	buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
}

dependencies {
	compile project(':deps:extension-api')
}


But the path is android\release\bin\deps\setbrightness

Looks like you pasted this:

classpath 'com.android.tools.build:gradle::ANDROID_GRADLE_PLUGIN::'

…instead of this:

classpath 'com.android.tools.build:gradle:::ANDROID_GRADLE_PLUGIN::'

You need all three colons in a row, since two will be removed, and you want to have one left over.

Ahh! Thanks.
Now I get past the old error but got a new one.

Export\android\release\bin\deps\setbrightness\src\main\java\org\haxe\extension\SetBrightness.java:139: package WindowManager does not exist
            WindowManager.LayoutParams layout = Extension.mainActivity.getWindow().getAttributes();
                         ^
1 error
:deps:setbrightness:compileReleaseJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':deps:setbrightness:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Well, actually my code is as below

	public static void setBrightness(float brightness) {
	    WindowManager.LayoutParams layout = Extension.mainActivity.getWindow().getAttributes();
	    layout.screenBrightness = brightness;
	    Extension.mainActivity.getWindow().setAttributes(layout);
	}

thanks

Add

import android.view.WindowManager;

to the top of file, or change

WindowManager.LayoutParams layout = Extension.mainActivity.getWindow().getAttributes();

to

android.view.WindowManager.LayoutParams layout = Extension.mainActivity.getWindow().getAttributes();

thanks a lot @restorer that did the trick.
Next question :slight_smile:

Now everything compiles but application is not launching if I call
SetBrightness.setBrightness(0.5);

But if I do not call this, then the application launches!

Thank you all for the help. The extension is now compiling fine.

But the application crashes, once I call the extension method.

Here are the codes

//SetBrightness.java
public static void testToast(int iVal){
		Toast.makeText(Extension.mainContext, "OpenFL : Toast", 5000).show();
	}

Haxe extension

//SetBrightness.hx
private static var testToastJNI = JNI.createStaticMethod("org.haxe.extension.SetBrightness", "testToast", "(I)V");	
	public static function testToast(testVal:Int):Void{
		trace('Extension Called : testToast : '+testVal);
		testToastJNI(testVal);
	}

Finally I am calling as this.

SetBrightness.testToast(2);

As soon as the last one is called, application crashes!

Figured out.

First of all
replace

import openfl.utils.JNI;

with

import lime.system.JNI;

Second, the java code must be inside Runnable as mentioned here.

1 Like