Android IDE (AIDE) Support Forum

AndroidX or v28+

I am now stuck due Android versions, to explain:
I run AIDE on a 5 year old Vodafone VDT1100 7" with 8GB + 16GB sd-card - UNROOTED.
The Android version is 6, Marshmallow or v23, or whatever is ment by all this gibberish - don’t understand this Google versioning anomaly anayway.

However I am trying to access my local storage “/storage/emulated/0/” with Manifest. READ/WRITE_EXTERNAL_FILES setup in manifest. Upon trying to write my own log file, due “LogCat” not accessible - I get an access denied error.

I then googled and stack-overflowed and followed the android official docs. it become clear I need to ask user permission.
The examples give the following:

boolean hasPermission = ( ContextCompat.checkSelfPermission( activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);
if ( ! hasPermission ) {
ActivityCompat.requestPermissions( parentActivity,
new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
REQUEST_WRITE_STORAGE );
}
@Override
public void onRequestPermissionsResult( final int code, final String[] reqs, final int[] rets ) {
super.onRequestPermissionsResult( code, reqs, rets );
switch( code ) {
case I_REQUEST_PERMISSIONS: {

I then realize I miss some android.support.v4 patch for ContextCompat and ActivityCompat to be resolved.
According to the official docs this v4 (v28) patch is not supported anymore and there is a lot of info on how to upgrade to AndroidX.

I then, according to the docs, I altered the build.gradle dependencies, eg-
classpath ‘com.android.support:support-v4:23.0.1’
Pressing the AIDE->Settings>Build&Run->Refresh Maven repo. Seem to flash the download icon for a second, but nothing comes in.

From further reading I then altered the settings.gradle to include the following-
android.useAndroidX=true
android.enableJetifier= true
Same effect - the download icon flash for a second but nothing seems updated.

This leave me now in doubt - can v6 firmware actualy handle v8+/9 upgrades, or am I stuck
with expired technology. I have no problem pointing SQLite db to the /storage/emulated/ and create fb files for debuging. - what are they doing different?

More, Google, only last week, pumped a new v6 firmware update into this Tab and thereafter some apps refuse to install.

Alternative does anybody know where I can find this AndroidX jar and go manually without this maven/gradle bull.
Frankly I never had any such issues with JDK or J2EE, not from Sun or Oracle since 2001, dump a jar in the libs dir and its there!
More this Dalvic VM can’t even reflect the .getFields() in declared order either, I had to compensate with annotations - inferior-ware!
:face_with_head_bandage:

I dont understand well but is okay:

To grant Android 21+ permissions without loses compatibility

public void grantPermission(String str) {
		if (checkSelfPermission(str) != PackageManager.PERMISSION_GRANTED
			&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new String[]{str}, 0);
		} else {
			Log.i("Native","Permission grant is not necessary");
		}
	}

To log a file in the Android’s LogCat

you cau use the cat shell command

public class FileUtils {
	public static String cat(String[] params, String url) {
		try {
			String args = String.join(" ", params);
			String fullcommand = "";
			fullcommand = "cat " + args + " " + url + "";
			Runtime r = Runtime.getRuntime();
			Process p = r.exec(fullcommand);
			System.out.println("Run: " + fullcommand);
			BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
			String response = null;
			String output = "";
			for (int x = 0; (response = stdInput.readLine()) != null; x++) {
				output += response + "\n";
			}
			while (p.isAlive()) {
				// NOTHING!
			}
			if (!p.isAlive()) {
				return String.join("\n", output);
			} else {
				return "this will never appear";
			}
		} catch (IOException e) {
			e.printStackTrace();
			return "Error: " + e.getMessage();
		}
	}
}

so then you can use with:

Log.i("Shell", FileUtils.cat(new String[] {
  "-v", "-E", "-T"
},"/your/file.jpg"));

This method is compatible whith another distros (like Ubuntu) too.

Thank you for the help!

  1. Regarding the V27 or 28 or AndroidX gradles, V27 downloaded properly, I am very impressed with AIDE, this is the gradles I used:
    Master

    apply plugin: ‘com.android.application’

android {
compileSdkVersion 21
buildToolsVersion “21.1.0”

defaultConfig {
    applicationId "upiva.spaza.app"
    minSdkVersion 14
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: ‘libs’, include: [’*.jar’])
}

Project gradle

apply plugin: ‘com.android.application’

android {
compileSdkVersion 27
buildToolsVersion “27.1.0”

defaultConfig {
    applicationId "upiva.spaza.app"
    minSdkVersion 18
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
implementation ‘com.android.support:appcompat-v7:27.1.0’
implementation ‘com.android.support:support-v4:27.0.0’
implementation fileTree(dir: ‘libs’, include: [’.jar’])
compile fileTree(dir: ‘libs’, include: [’
.jar’])
}
that seemingly installed correctly!

However when I extend a MyActivity from AppCompatActivity it crashes!

  1. Regarding the logging, I’m on a non-rooted device - no matter how hard I try I just can’t see the logcat.
    So I created this logger called Lgx - that logs to the Android cache and I have no problem viewing my own apps logs.
    Anybody feel free to use it if you think it can help, just call Lgx.init( , , msg… ) from a custom Application class.

    package upiva.spaza.app.utl.gen;

import android.content.Context;
import android.util.Log;
import java.io.File;
import java.io.FileWriter;
import java.util.Date;

public enum Lgx {

/// Constants

// never trust enum.ordinsls!
FAIL( 0 ),
WARN( 1 ),
NWTF( 2 ),
DBUG( 3 ),
INFO( 4 ),
FINE( 5 ),
MORE( 6 ),
MOST( 7 ),
VRBS( 9 );

private static int sMask = 0;
private Lgx( final int mask ) {
sMask = mask;
}

/// Inners

// fluent arg. evaluator
public static class Eval {

/// Members

private final StackTraceElement mElem;

/// Construction

private Eval() { 
  super();
  mElem = _stax_( 2 );
}


/// Methods

public Eval notNull( final String para, final Object data ) {
  if( data == null ) {
	_logx_( null, mElem, String.format( "Argument '%s' required!", para ) );
  }
  return this;
}

public Eval notNull( final String para, final Object[] data ) {
  if( data == null ) {
	_logx_( null, mElem, String.format( "Array argument '%s' of not zero-length required!", para ) );
  }
  return this;
}

public Eval notMinVal( final String para, final long data, final long minv ) {
  if( data < minv ) {
	_logx_( null, mElem, String.format( "Argument '%s' of min-value( %d ) required!", para, minv ) );
  }
  return this;
}

public Eval notMaxVal( final String para, final long data, final long maxv ) {
  if( data > maxv ) {
	_logx_( null, mElem, String.format( "Argument '%s' of max-value( %d ) required!", para, maxv ) );
  }
  return this;
}

public Eval notMinMaxVal( final String para, final long data, final long minv, final long maxv ) {
  if( ( data < minv ) || ( data > maxv ) ) {
	_logx_( null, mElem, String.format( "Argument '%s' of min-value( %d ) - max-value( %d ) required!", para, minv, maxv ) );
  }
  return this;
}

public Eval notMinDbl( final String para, final double data, final double minv ) {
  if( data < minv ) {
	_logx_( null, mElem, String.format( "Argument '%s' of min-value( %d ) required!", para, minv ) );
  }
  return this;
}

public Eval notMaxDbl( final String para, final double data, final double maxv ) {
  if( data > maxv ) {
	_logx_( null, mElem, String.format( "Argument '%s' of max-value( %d ) required!", para, maxv ) );
  }
  return this;
}

public Eval notMinMaxDbl( final String para, final double data, final double minv, final double maxv ) {
  if( ( data < minv ) || ( data > maxv ) ) {
	_logx_( null, mElem, String.format( "Argument '%s' of min-value( %d ) - max-value( %d ) required!", para, minv, maxv ) );
  }
  return this;
}

public Eval notText( final String para, final String text ) {
  if( ( text == null ) || text.isEmpty() ) {
	_logx_( null, mElem, String.format( "Argument '%s' required!", para ) );
  }
  return this;
}

public Eval notMinLen( final String para, final String text, final long minl ) {
  if( ( text == null ) || text.isEmpty() || ( text.length() < minl ) ) {
	_logx_( null, mElem, String.format( "Argument '%s' of min-length( %d ) required!", para, minl ) );
  }
  return this;
}

public Eval notMaxLen( final String para, final String text, final long maxl ) {
  if( ( text == null ) || text.isEmpty() || ( text.length() > maxl ) ) {
	_logx_( null, mElem, String.format( "Argument '%s' of max-length( %d ) required!", para, maxl ) );
  }
  return this;
}

public Eval notMinMaxLen( final String para, final String text, final long minl, final long maxl ) {
  if( ( text == null ) || text.isEmpty() || ( text.length() < minl) || ( text.length() > maxl ) ) {
	_logx_( null, mElem, String.format( "Argument '%s' of min-length( %d ) - max-length( %d ) required!", para, minl, maxl ) );
  }
  return this;
}

}//-Eval

/// Members

private static File sFile = null;
private static Lgx sMode = Lgx.DBUG;

/// Construction

private Lgx( ) {}

/// Helpers

private static StackTraceElement stax( final int indx ) {
StackTraceElement[] _arry = null;
try {
throw new Exception( “-hack-” );
} catch( Exception e ) {
_arry = e.getStackTrace();
}
return _arry[ indx ];
}

private static String logx( final Lgx mode, final StackTraceElement stax, final String msgs ) {
// always log fail + warn + nwtf
if( mode.sMask > NWTF.sMask ) {
if( mode.sMask > sMode.sMask )
return “”;
}
// prep message
final String text = String.format( “%s: @%s [%d]\n\t%s”, mode.name(), stax.getClassName(), stax.getLineNumber(), msgs );
if( sFile != null ) {
// append
try {
final FileWriter w = new FileWriter( sFile, true );
w.append( text );
w.append( “\n” );
w.flush();
w.close();
} catch( Exception e ) {
e.printStackTrace();
Log.e( “Lgx.logx”, e.toString() );
}
}
// droid logging
switch( mode ) {
case FAIL:
Log.e( “Lgx.logx”, text );
throw new RuntimeException( text );
case WARN:
Log.w( “Lgx.logx”, text );
return text;
case NWTF:
Log.wtf( “Lgx.logx”, text );
return text;
case DBUG:
Log.d( “Lgx.logx”, text );
return text;
case INFO:
case FINE:
case MORE:
case MOST:
Log.i( “Lgx.logx”, text );
return text;
case VRBS:
Log.v( “Lgx.logx”, text );
return text;
default:
throw new RuntimeException( "Lgx; Unknown mask: " + text );
}
}

/// Utilities

public static void fail( final String frmt, final Object… args ) {
logx( Lgx.FAIL, stax( 2 ), String.format( frmt, args ) );
}//-fail

public static void fail( final Throwable e ) {
final StackTraceElement x = ( e != null ) ? e.getStackTrace()[ 1 ] : stax( 2 );
logx( Lgx.FAIL, x, x.toString() );
}//-fail

public static void fail( final Throwable e, final String frmt, final Object… args ) {
final StackTraceElement x = ( e != null ) ? e.getStackTrace()[ 1 ] : stax( 2 );
String _text = String.format( frmt, args );
_text = _text + "\nDue: " + x.toString();
logx( Lgx.FAIL, x, _text );
}//-fail

public static String warn( final String frmt, final Object… args ) {
return logx( Lgx.WARN, stax( 2 ), String.format( frmt, args ) );
}//-warn

public static String nwtf( final String frmt, final Object… args ) {
return logx( Lgx.NWTF, stax( 2 ), String.format( frmt, args ) );
}//-most

public static String dbug( final String frmt, final Object… args ) {
return logx( Lgx.DBUG, stax( 2 ), String.format( frmt, args ) );
}//-dbug

public static String info( final String frmt, final Object… args ) {
return logx( Lgx.INFO, stax( 2 ), String.format( frmt, args ) );
}//-info

public static String fine( final String frmt, final Object… args ) {
return logx( Lgx.FINE, stax( 2 ), String.format( frmt, args ) );
}//-info

public static String more( final String frmt, final Object… args ) {
return logx( Lgx.MORE, stax( 2 ), String.format( frmt, args ) );
}//-info

public static String most( final String frmt, final Object… args ) {
return logx( Lgx.MOST, stax( 2 ), String.format( frmt, args ) );
}//-info

public static String vrbs( final String frmt, final Object… args ) {
return logx( Lgx.VRBS, stax( 2 ), String.format( frmt, args ) );
}//-most

public static Eval eval() {
return new Eval();
}//-eval

/// Factory

public static void init( final Context cntx, final Lgx mode, final String frmt, final Object… args ) {
if( cntx == null )
throw new IllegalArgumentException( “Lgx.init; Context argument required !” );
sMode = mode;
if( sFile == null ) {
final Date date = new Date( System.currentTimeMillis( ) );
String _name = String.format( “%tF%tR.txt”, date, date );
_name = _name.replace( “-”, “” ).replace( “:”, “” );
File _file = cntx.getExternalCacheDir();
sFile = new File( _file, _name );
}
logx( Lgx.INFO, stax( 2 ), String.format( frmt, args ) );
}//-init

public static void shut( final String frmt, final Object… args ) {
logx( Lgx.INFO, stax( 2 ), String.format( frmt, args ) );
//sFile = null;
}//-shut

}//-eoc

l should very much appreciate it if someone can publish a grsdle.build for a minimal working set for AndroidX.

Refer to this link


It contains a working example with androidx.

1 Like