Fixed some minor bugs

- Backup before implementing terminal
- Fixed shebang issue in Gradle executable
- Clean all binary files in JDK (earlier it only cleaned binaries in bin directory)
- If the CodeEditor is not editable, do not show cut and paste options in text action mode
- Some more changes
This commit is contained in:
Akash Yadav
2021-08-25 21:07:19 +05:30
parent a8d79291e3
commit b69fa9d401
17 changed files with 135 additions and 41 deletions
@@ -102,7 +102,7 @@ public class DownloadActivity extends StudioActivity {
}
}
sb.append("rm -rf '" + getApp().getToolsDownloadDirectory().getAbsolutePath() + "' && ");
sb.append("echo 'Cleaning unsupported flags in binaries...' && $BUSYBOX find $JAVA_HOME/bin -type f -exec androidide-cleaner {} \\; && ");
sb.append("echo 'Cleaning unsupported flags in binaries...' && $BUSYBOX find $JAVA_HOME -type f -exec androidide-cleaner {} \\; && ");
sb.append("echo " + DONE);
server.bgAppend(sb.toString());
}
@@ -115,6 +115,8 @@ public class DownloadActivity extends StudioActivity {
if(line.contains(DONE)) {
getApp().getPrefManager().putBoolean(PreferenceManager.KEY_FRAMEWORK_INSTALLED, true);
showRestartNeeded();
if(getProgressSheet().isShowing())
getProgressSheet().dismiss();
}
});
}
@@ -232,6 +232,7 @@ public class MainActivity extends StudioActivity implements View.OnClickListener
private void createProgressSheet() {
mProgressSheet = new ProgressSheet();
mProgressSheet.setShowShadow(false);
}
private void setMessage(int msg) {
@@ -39,6 +39,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import com.blankj.utilcode.util.FileUtils;
public class StudioApp extends MultiDexApplication
{
@@ -364,8 +365,11 @@ public class StudioApp extends MultiDexApplication
File gradle = new File(Environment.GRADLE_DIR, "bin/gradle");
if(gradle.exists()) {
String[] txt = FileUtil.readFile(gradle.getAbsolutePath()).split("\n");
if(txt != null && txt.length > 1 && txt[0].contains("#!/usr/bin/env sh")) {
txt[0] = "";
if(txt != null && txt.length > 1) {
String line1 = txt[0];
if(line1.startsWith("#!")) {
txt[0] = "";
}
FileUtil.writeFile(gradle.getAbsolutePath(), TextUtils.join("\n", txt));
if(!gradle.canExecute())
gradle.setExecutable(true);
@@ -1,26 +1,25 @@
package com.itsaky.androidide.fragments.preferences;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.ZipUtils;
import com.blankj.utilcode.util.ThreadUtils;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.itsaky.androidide.R;
import com.itsaky.androidide.app.StudioApp;
import com.itsaky.androidide.databinding.LayoutDialogTextInputBinding;
import com.itsaky.androidide.databinding.LayoutInstallToolsBinding;
import com.itsaky.androidide.fragments.sheets.ProgressSheet;
import com.itsaky.androidide.fragments.sheets.TextSheetFragment;
import com.itsaky.androidide.shell.ShellServer;
import com.itsaky.androidide.tasks.TaskExecutor;
import com.itsaky.androidide.utils.Environment;
import com.itsaky.toaster.Toaster;
import java.io.File;
import java.util.List;
import java.util.Set;
import static com.itsaky.androidide.managers.PreferenceManager.*;
import com.itsaky.androidide.utils.Logger;
public class BuildPreferences extends BasePreferenceFragment implements Preference.OnPreferenceClickListener {
@@ -53,7 +52,7 @@ public class BuildPreferences extends BasePreferenceFragment implements Preferen
categoryGradle.setTitle(R.string.gradle);
categoryGradle.addPreference(customCommands);
categoryGradle.addPreference(clearCache);
setPreferenceScreen(screen);
customCommands.setOnPreferenceClickListener(this);
@@ -70,7 +69,7 @@ public class BuildPreferences extends BasePreferenceFragment implements Preferen
}
return true;
}
private void showGradleCommandsDialog() {
final String[] labels = {
"--stacktrace",
@@ -125,7 +124,7 @@ public class BuildPreferences extends BasePreferenceFragment implements Preferen
}
private Object deleteCaches() {
File file = new File(Environment.HOME, ".gradle/caches");
File file = new File(Environment.GRADLE_USER_HOME, "caches");
if(file.exists()) {
FileUtils.delete(file);
}
@@ -45,7 +45,7 @@ public class TextSheetFragment extends BaseBottomSheetFragment {
protected void onShow() {
super.onShow();
editor.setText(getOutputBuilder());
}
}
private Void scrollToBottom() {
if(getActivity() != null)
@@ -39,7 +39,7 @@ public class ToolsManager {
if(onFinish != null)
onFinish.run();
}
private static void writeInitScript(StudioApp app) {
FileIOUtils.writeFileFromString(Environment.INIT_SCRIPT, INIT_SCRIPT);
}
@@ -38,34 +38,33 @@ public class ShellServer extends Thread {
stringBuilder.append("\nexport ANDROID_HOME=" + Environment.path(Environment.ANDROID_HOME));
stringBuilder.append("\nexport GRADLE_INSTALLATION_DIR=" + Environment.path(Environment.GRADLE_DIR));
stringBuilder.append("\nexport GRADLE_USER_HOME=" + Environment.path(Environment.GRADLE_USER_HOME));
stringBuilder.append("\nexport JLS_HOME=" + Environment.path(Environment.JLS_HOME));
stringBuilder.append("\nexport PATH=$PATH:$HOME/bin");
stringBuilder.append("\nexport PATH=$PATH:" + Environment.path(Environment.JAVA_HOME) + "/bin");
stringBuilder.append("\nexport PATH=$PATH:" + Environment.path(Environment.GRADLE_DIR) + "/bin");
stringBuilder.append("\nexport PATH=$PATH:" + Environment.path(Environment.ANDROID_HOME) + "/cmdline-tools/latest/bin");
stringBuilder.append("\nexport PATH=$PATH:" + Environment.path(Environment.ANDROID_HOME) + "/cmake/bin");
stringBuilder.append("\nexport PATH=$PATH:" + Environment.path(Environment.BINDIR));
stringBuilder.append("\nexport JLS_HOME=" + Environment.path(Environment.JLS_HOME));
// Provide paths to .so files needed to execute JDK
final String lib = Environment.LIBDIR.getAbsolutePath();
stringBuilder.append("\nexport LD_LIBRARY_PATH=" + lib);
stringBuilder.append(System.getenv().containsKey("LD_LIBRARY_PATH") ? ":" + System.getenv().get("LD_LIBRARY_PATH") : "");
if(android.os.Build.VERSION.SDK_INT >= 30) {
// Hook calls to malloc() in native binaries
// Required only in Android 11 and up
stringBuilder.append("\nexport LD_PRELOAD=" + Environment.LIBHOOKSO.getAbsolutePath());
}
//// Provide paths to .so files needed to execute JDK
// final String lib = Environment.LIBDIR.getAbsolutePath();
// stringBuilder.append("\nexport LD_LIBRARY_PATH=" + lib);
// stringBuilder.append(System.getenv().containsKey("LD_LIBRARY_PATH") ? ":" + System.getenv().get("LD_LIBRARY_PATH") : "");
//
// if(android.os.Build.VERSION.SDK_INT >= 30) {
// // Hook calls to malloc() in native binaries
// // Required only in Android 11 and up
// stringBuilder.append("\nexport LD_PRELOAD=" + Environment.LIBHOOKSO.getAbsolutePath());
// }
// Monotonic clock fix, needed for JDK
stringBuilder.append("\nln -sf /apex/com.android.runtime/lib64/bionic/libc.so " + lib + "/librt.so && " +
"ln -sf /apex/com.android.runtime/lib64/bionic/libc.so " + lib + "/libpthread.so");
stringBuilder.append("\nln -sf /apex/com.android.runtime/lib64/bionic/libc.so $JAVA_HOME/lib/librt.so && ln -sf /apex/com.android.runtime/lib64/bionic/libc.so $JAVA_HOME/lib/libpthread.so");
// Execute all commands...
append(stringBuilder.toString(), false);
// Make sure there are proper permissions set to the $HOME directory
append("chmod -R 777 $HOME", false);
append("chmod -R 777 $HOME > /dev/null 2>&1", false);
} catch (Throwable th) {
if (callback != null) {
String out = ThrowableUtils.getFullStackTrace(th).concat("\n");
@@ -27,7 +27,7 @@ public final class Environment {
public static File GRADLE_PLUGIN;
public static File BOOTCLASSPATH;
public static File CACHES_DIR;
public static File AAPT2;
public static File AAPT2_DIR;
public static File INIT_SCRIPT;
public static File LIBHOOKSO;
@@ -79,7 +79,7 @@ public final class Environment {
LIBHOOKSO = new File(LIBDIR, "libhook.so");
CACHES_DIR = new File(HOME, "ide-caches");
BOOTCLASSPATH = new File("");
AAPT2 = new File(files21, "com.android.tools.build/aapt2/4.0.1-6197926");
AAPT2_DIR = new File(files21, "com.android.tools.build/aapt2");
GRADLE_PLUGIN = new File(files21, "com.itsaky.androidide/gradle");
GRADLE_USER_HOME = new File(HOME, ".gradle");
GRADLE_PROPS = new File(GRADLE_USER_HOME, "gradle.properties");
@@ -7,15 +7,15 @@ import io.github.rosemoe.editor.widget.CodeEditor;
public class Editor extends CodeEditor {
public Editor(Context context) {
super(context, null);
this(context, null);
}
public Editor(Context context, AttributeSet attrs) {
super(context, attrs, 0);
this(context, attrs, 0);
}
public Editor(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr, 0);
this(context, attrs, defStyleAttr, 0);
}
public Editor(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
@@ -63,10 +63,10 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.itsaky.androidide.R;
import com.itsaky.androidide.databinding.LayoutDialogTextInputBinding;
import com.itsaky.androidide.interfaces.JLSRequestor;
import com.itsaky.androidide.managers.VersionedFileManager;
import com.itsaky.androidide.syntax.colorschemes.SchemeAndroidIDE;
import com.itsaky.androidide.utils.Logger;
import com.itsaky.androidide.utils.TypefaceUtils;
import com.itsaky.androidide.utils.VersionedFileManager;
import com.itsaky.lsp.Diagnostic;
import com.itsaky.lsp.DiagnosticSeverity;
import com.itsaky.lsp.DidChangeTextDocumentParams;
@@ -65,17 +65,21 @@ class EditorTextActionModeStarter implements CodeEditor.EditorTextActionPresente
.setShowAsActionFlags(2)
.setIcon(array.getDrawable(0));
menu.add(0, 1, 0, mEditor.getContext().getString(android.R.string.cut))
.setShowAsActionFlags(2)
.setIcon(array.getDrawable(1));
if(mEditor.isEditable()) {
menu.add(0, 1, 0, mEditor.getContext().getString(android.R.string.cut))
.setShowAsActionFlags(2)
.setIcon(array.getDrawable(1));
}
menu.add(0, 2, 0, mEditor.getContext().getString(android.R.string.copy))
.setShowAsActionFlags(2)
.setIcon(array.getDrawable(2));
menu.add(0, 3, 0, mEditor.getContext().getString(android.R.string.paste))
.setShowAsActionFlags(2)
.setIcon(array.getDrawable(3));
if(mEditor.isEditable()) {
menu.add(0, 3, 0, mEditor.getContext().getString(android.R.string.paste))
.setShowAsActionFlags(2)
.setIcon(array.getDrawable(3));
}
menu.add(0, 4, 0, mEditor.getContext().getString(com.itsaky.androidide.R.string.menu_navigate_definition))
.setIcon(com.itsaky.androidide.R.drawable.ic_goto_definition);
Binary file not shown.
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#ffffff"
android:pathData="M21.83,4C22.32,4 22.63,4.4 22.5,4.89L19.34,19.11C19.23,19.6 18.75,20 18.26,20H2.17C1.68,20 1.37,19.6 1.5,19.11L4.66,4.89C4.77,4.4 5.25,4 5.74,4H21.83M15.83,16H11.83C11.37,16 11,16.38 11,16.84C11,17.31 11.37,17.69 11.83,17.69H15.83C16.3,17.69 16.68,17.31 16.68,16.84C16.68,16.38 16.3,16 15.83,16M5.78,16.28C5.38,16.56 5.29,17.11 5.57,17.5C5.85,17.92 6.41,18 6.81,17.73C14.16,12.56 14.21,12.5 14.26,12.47C14.44,12.31 14.53,12.09 14.54,11.87C14.55,11.67 14.5,11.5 14.38,11.31L9.46,6.03C9.13,5.67 8.57,5.65 8.21,6C7.85,6.32 7.83,6.88 8.16,7.24L12.31,11.68L5.78,16.28Z"/>
</vector>
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#ffffff"
android:pathData="M21,10.12H14.22L16.96,7.3C14.23,4.6 9.81,4.5 7.08,7.2C4.35,9.91 4.35,14.28 7.08,17C9.81,19.7 14.23,19.7 16.96,17C18.32,15.65 19,14.08 19,12.1H21C21,14.08 20.12,16.65 18.36,18.39C14.85,21.87 9.15,21.87 5.64,18.39C2.14,14.92 2.11,9.28 5.62,5.81C9.13,2.34 14.76,2.34 18.27,5.81L21,3V10.12M12.5,8V12.25L16,14.33L15.28,15.54L11,13V8H12.5Z"/>
</vector>
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/path"
android:layout_marginBottom="8dp"
android:hint="@string/msg_path_to_tools"
app:startIconDrawable="@drawable/ic_file_rename"
app:startIconTint="@color/primaryIconColor"
app:counterEnabled="true"
app:counterMaxLength="40">
<com.google.android.material.textfield.TextInputEditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:singleLine="true"/>
</com.google.android.material.textfield.TextInputLayout>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/msg_delete_aapt2"
android:id="@+id/delete_aapt"
android:layout_marginBottom="8dp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/msg_delete_jdk"
android:id="@+id/delete_jdk"
android:layout_marginBottom="8dp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/msg_delete_gradle"
android:id="@+id/delete_gradle"
android:layout_marginBottom="8dp"/>
</LinearLayout>
+11 -1
View File
@@ -1,4 +1,12 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="msg_shell_verbose">Verbose output is enabled!</string>
<string name="msg_shell_output">Shell output</string>
<string name="msg_invalid_path">Invalid path!</string>
<string name="msg_path_to_tools">Path to .tar.xz or .zip</string>
<string name="str_build_tools">Build Tools</string>
<string name="msg_delete_aapt2">Delete AAPT2</string>
<string name="msg_delete_jdk">Delete JDK</string>
<string name="msg_delete_gradle">Delete Gradle</string>
<string name="group_project">Project</string>
<string name="title_close_project">Close this project</string>
<string name="msg_opened_project_does_not_exist">Last opened project doesn\'t exist!</string>
@@ -97,10 +105,12 @@
<string name="msg_custom_gradle">Please type/paste the path of .zip file which contains Gradle executables.</string>
<string name="msg_gradle_installed">Gradle Installed successfully!</string>
<string name="msg_editor_font_size">Please choose default font size of editor :</string>
<string name="msg_clear_cache">This will delete caches directory created by Gradle. If you delete it, the next build may take a bit longer than normal as Gradle will download required files again.\n\nAre you sure you want to delete caches?</string>
<string name="msg_clear_cache">This will delete caches directory created by Gradle. If you delete it, the next build may take a bit longer than normal as Gradle will download required files again.\nIMPORTANT: This will also delete AAPT2. You will need to reinstall it otherwise you\'ll end up with a build failure.\n\nAre you sure you want to delete caches?</string>
<string name="msg_install_gradle">Currently installed gradle version will be DELETE PEEMANENTLY!\n\nPlease enter full path of the zip file which contains Gradle distribution.</string>
<string name="reset">Reset</string>
<string name="title_change_text_size">Editor font size</string>
<string name="idepref_update_tools_title">Update/Install build tools</string>
<string name="idepref_update_tools_msg">Use this if you want to install or update build tools.</string>
<string name="idepref_about_title">About AndroidIDE</string>
<string name="idepref_build_clearCache_title">Clear Gradle caches</string>
<string name="idepref_build_clearCache_summary">Clear Gradle caches directory. This will delete all dependencies downloaded by Gradle. Required files will be downloaded again in next build.</string>