Faraaz Kurawle
Faraaz Kurawle

Reputation: 1182

d8/dx --help gives no output / d8.bat not working

I am trying to build android apk manually without using Android Studio or gradle. I have set my environment variables perfectly that is ANDROID_HOME and JAVA_HOME are correctly set. I am able to run aapt and also get output from it when i use --help argument, but with d8.bat i am not able to do so.

d8 was working correctly until i decided to redownload SDK and others tools from stract using sdkmanager and now d8 is not working correctly.

I am new to Android so i dont have any direction on how to fix this issue and my decision to manually build android apps is due to the fact my computer can not handle android studio or gradle.

Even Android Docs says there's an argument --help so it must be working but I dont know why my d8 is not working correctly.

Android SDK version: 30.0.3

Note: I have manually added echo "Hello World" to test if there isn't any problem to access it, and I can get the output as "Hello World" only now.

@echo off
REM Copyright (C) 2018 The Android Open Source Project
REM
REM Licensed under the Apache License, Version 2.0 (the "License");
REM you may not use this file except in compliance with the License.
REM You may obtain a copy of the License at
REM
REM     http://www.apache.org/licenses/LICENSE-2.0
REM
REM Unless required by applicable law or agreed to in writing, software
REM distributed under the License is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM See the License for the specific language governing permissions and
REM limitations under the License.

REM don't modify the caller's environment
setlocal

REM Locate d8.jar in the directory where d8.bat was found and start it.

REM Set up prog to be the path of this script, including following symlinks,
REM and set up progdir to be the fully-qualified pathname of its directory.
set prog=%~f0
echo "Hello WOrld"
rem Check we have a valid Java.exe in the path.
set java_exe=
if exist    "%~dp0..\tools\lib\find_java.bat" call    "%~dp0..\tools\lib\find_java.bat"
if exist "%~dp0..\..\tools\lib\find_java.bat" call "%~dp0..\..\tools\lib\find_java.bat"
if not defined java_exe goto :EOF

set jarfile=d8.jar
set "frameworkdir=%~dp0"
rem frameworkdir must not end with a dir sep.
set "frameworkdir=%frameworkdir:~0,-1%"

if exist "%frameworkdir%\%jarfile%" goto JarFileOk
    set "frameworkdir=%~dp0lib"

if exist "%frameworkdir%\%jarfile%" goto JarFileOk
    set "frameworkdir=%~dp0..\framework"

:JarFileOk

set "jarpath=%frameworkdir%\%jarfile%"

set javaOpts=
set args=

REM By default, give d8 a max heap size of 1 gig and a stack size of 1meg.
rem This can be overridden by using "-JXmx..." and "-JXss..." options below.
set defaultXmx=-Xmx1024M
set defaultXss=-Xss1m

REM Capture all arguments that are not -J options.
REM Note that when reading the input arguments with %1, the cmd.exe
REM automagically converts --name=value arguments into 2 arguments "--name"
REM followed by "value".
set params=

:firstArg
if [%1]==[] goto endArgs
set a=%~1

    if [%defaultXmx%]==[] goto notXmx
    if %a:~0,5% NEQ -JXmx goto notXmx
        set defaultXmx=
    :notXmx

    if [%defaultXss%]==[] goto notXss
    if %a:~0,5% NEQ -JXss goto notXss
        set defaultXss=
    :notXss

    if %a:~0,2% NEQ -J goto notJ
        set javaOpts=%javaOpts% -%a:~2%
        shift /1
        goto firstArg

    :notJ
    set params=%params% %1
    shift /1
    goto firstArg

:endArgs

set javaOpts=%javaOpts% %defaultXmx% %defaultXss%
call "%java_exe%" %javaOpts% -Djava.ext.dirs="%frameworkdir%" -cp "%jarpath%" com.android.tools.r8.D8 %params%

Upvotes: 1

Views: 39

Answers (1)

Faraaz Kurawle
Faraaz Kurawle

Reputation: 1182

I found a workaround that involves using d8.jar get d8.bat functionality. Actually d8.bat is just a helper file which calls d8.jar provide its functionality.

STEP 1: locate d8.jar. Its found under SDK\build-tools\30.0.3\lib\d8.jar

STEP 2: use java to call d8.jar.

Syntax:

java -cp <path_to_d8.jar> com.android.tools.r8.D8 <D8_arguments>

Refrences:

  1. Stackoverflow answer 1
  2. Stackoverflow answer 2

Upvotes: 0

Related Questions