Jenkins - Warnings Plugin & IntelliJ IDEA Parser - android

I am having issues opening the files that contains IntelliJ IDEA Inspection warnings using Jenkins and Warnings Plugin.
The path to my files looks weird - file://$PROJECT_DIR$/app/src/main..../Foo.java in the .xml generated files by ./inspect.sh
When I click on the file I get the following error:
`java.io.IOException: Failed to copy file:/$PROJECT_DIR$/app/src/main/java`/
These are some screenshots of my files:
I am using the ./inspect.sh from Android Studio, not from actual IntelliJ. Could that be the problem?
Thanks in advance.

In the end I have added an extra build step where I clean the .xml files that are output by ./inspect.sh.
I have also added a line of code that removes all the inspects related to the build (generated) directory. Hope this helps anyone who was stuck with this issue.
Below you have the tweaked inspect.sh file and the two separate build steps:
inspect.sh
#!/bin/sh
#
# ------------------------------------------------------
# Android Studio offline inspection script.
# ------------------------------------------------------
#
export DEFAULT_PROJECT_PATH="$(pwd)"
cd ..
exec "MacOS/studio" inspect "$#"
Build Step 1
cd ${WORKSPACE}/inspectionsresults
rm *.xml
cd "${ANDROID_STUDIO_HOME_BIN}"
./inspect.sh ${WORKSPACE} ${WORKSPACE}/inspections_profile.xml ${WORKSPACE}/inspectionsresults -v2 -d ${WORKSPACE}/app
Build Step 2
cd ${WORKSPACE}/inspectionsresults
sed -i .bak "s,file://\\\$PROJECT_DIR\\\$,${WORKSPACE},g" *.xml
sed -i .bak "s,file:///,,g" *.xml
/usr/local/bin/xml ed -L -d "/problems/problem[contains(file,'generated')]" *.xml
rm *.bak
I have used xmlstarlet to remove the "generated" problems.
brew install xmlstarlet

Related

How to check obfuscation results of flutter app?

In native android development I could check whether my minifyEnabled had taken effect.
I used this script (in linux) which allows me to extract the apk and view the java files to see if my code is readable, or has been obfuscated :
#! /bin/bash
d2j=/work/installs/dex2jar-2.0
jdgui=/work/installs/jd-gui-1.4.0.jar
apk_loc=/work/projects/my_app/build/app/outputs/app-release.apk
mkdir -p /work/tmp/dex
rm -rf /work/tmp/dex/*
cd /work/tmp
cp $apk_loc ./app-release.zip
unzip app-release.zip -d dex
cd dex
chmod +x $d2j/*.sh
$d2j/d2j-dex2jar.sh classes.dex
java -jar $jdgui classes-dex2jar.jar
If I use this script on a flutter apk, I don't see any files containing anything related to my original code.
Flutter's dart code is compiled to native and embedded to flutter.so runtime, so decompiling flutter is not as easy as byte code of java/kotlin
However decompiling .so file is possible. You can use the toolchains inside the android ndk to perform the type of disassembling you want to
./android-ndk-r15b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-objdump -T "flutter.so | less
but this is just give you an objdump.

Reduce Android Studio Project Size

I want to reduce Android Studio project size to save it for after use
In MS Visual Studio, we can delete *.ipch, *.sdf and Debug files to reduce the project size
I see app/build/intermediates folder is really large, can I delete this folder?
Yes, you can safely delete the intermediates folder. You can even delete the whole build folder that contains intermediates.
The build folder and it's contents will be re-generated the next time you run/build your project though.
In Android Studio, go to the Terminal window. If you did not go to a different directory since you opened the IDE, you should find yourself on the top level of your project folder (something like ../Android Studio/projectname). There you simply type
./gradlew clean
That's it. I just reduced my project folder size from 589 MB to 21 MB.
The file .gitignore containted in the project created by AndroidStudio lists all files / patterns not to be stored in the git repository, i.e. those files that are not required for building the project. Therefore, it should be safe to remove all files / directories matching the patterns listed in the .gitignore file.
In my projects it lists:
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
Please find the batch file I use to do that.
Set the batch under the root of your project directories.
Hoping it helps.
#rem ##########################################################################
#rem
#rem Export an ANDROID STUDIO application
#rem
#rem ##########################################################################
echo off
CLS
echo _________________________________________
echo ANDROID-STUDIO files sources export
echo _________________________________________
echo
echo If directory name includes space
echo - Surround name with quotes
echo _________________________________________
set /p dirname= Dir name to export :
if %dirname% == "" goto ERROR
set str=%dirname%
mkdir c:\EXPORT\%str%
pause
xcopy %dirname% c:\EXPORT\%str% /s
del c:\EXPORT\%str%\*.iml
del c:\EXPORT\%str%\app\*.apk
rmdir c:\EXPORT\%str%\.gradle /s /q
rmdir c:\EXPORT\%str%\.idea /s /q
rmdir c:\EXPORT\%str%\build /s /q
erase c:\EXPORT\%str%\app\build /f /s /q
rmdir c:\EXPORT\%str%\app\build /s /q
pause
goto END
:ERROR
echo Cannot create, check the directory root
goto OUT
:END
CLS
echo _________________________________________
echo ANDROID-STUDIO EXPORT
echo _________________________________________
echo Export ended, check c:\EXPORT
:OUT
pause
In Android Studio:
Click on Graddle >> app >> build >> and double click on "clean"
Mac & Linux users:
In terminal type ./gradlew clean in the root of your android project.
Windows users:
In cmd paste gradlew clean in the root of your android project.

Building webrtc library

I am trying to build webrtc android demo application. I was following README applied by the project. First thing was mentioned about gclient but when i tried to run it "no external or internal command". Then i got this link according to the this link i cloned the depot_tool repository but when at the step when i try to run gclient i got this
So after hours of trying i am not able to run it. if any one has experience with this WebRTC library please provide some help. Any guidance? Any Hlep will be appreciated
I heard few things were changed from svn to GIT. We tried building webRTC to windows7 using visual studio. See if you can use any parts on this.
Get depot_tools software and extract to a location (set this path in environment variable).
cd to depot_tools directory and hit 'gclient' (this should take sometime)
Install python 2.7 and put it path.
create a folder of your choice for webRTC and open command prompt there.
Now hit, gclient config http://webrtc.googlecode.com/svn/trunk
then, gclient sync.
Then set GYP_GENERATORS=msvs environment variable (use ninja if you want that).
Also set msvs_version=2012 (depending on your visual studio version)
now run, gclient runhooks --force
This should generate solutions files for your folder. fireup the libjingle/webrtc.sln files and start building it. I'm not sure if it builds as is. But we had hicupps with that.
See this link on WebRTC native development if you haven't already. From my personal experience building this tricky job initially.
Also note that links might be deprecated as they moved to git, don't know if they are still maintaining it.
How to compile WEBRTC On ubuntu
download script and run:
https://cs.chromium.org/chromium/src/build/install-build-deps.sh
./build/install-build-deps.sh --no-chromeos-fonts
Now download depot tools
$ git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git
Put it in Path
$ export PATH=`pwd`/depot_tools:"$PATH"
Define your settings:
export GYP_DEFINES="target_arch=x64 host_arch=x64 build_with_chromium=0 use_openssl=0 use_gtk=0 use_x11=0 include_examples=0 include_tests=1 fastbuild=1 remove_webcore_debug_symbols=1 include_pulse_audio=0 include_internal_video_render=0 clang=1 "
make file to download the source
mkdir webrtc-checkout
cd webrtc-checkout
I chose branch 50 you can change it
gclient config https://chromium.googlesource.com/external/webrtc.git#branch-heads/50 --name=src
gclient sync --force --with_branch_heads
gclient sync --force --with_branch_heads --nohooks
cd src
git checkout branch-heads/50
gclient runhooks
ninja -C ./out/Release
Collect your LIB & Include file to use it in your project
mkdir ../lib/
find ./ -name "*.o" -and -not -name do_not_use -and -not -name protoc -and -not -name genperf -exec ar crs ../lib/libwebrtc.a {} +
mkdir ../include
find ./ -name *.h -exec cp --parents '{}' ../include ';'

Creating Project Cocos2d-x-3.1.1

I have downloaded Cocos2d-x-3.1.1 but it does not include #create-android-project.bat and #create-android-project.sh then i download these 2 files from the internet and i tried to create project i receive the error. anyone have any idea please kindly help.
.............
Resolved location library project to C:\ADT\cocos2d-x\cocos2dx\platform\android\java
Error: Project folder 'C:\ADT\cocos2d-x\cocos2dx\platform\android\java' is not valid directory
Error: No Android manifest at: C:\ADT\cocos2d-x\cocos2dx\platform\android\java
Error!!!
Don't run in cygwin. You should run corresponding bat.
Press any key to continue.
$ cocos new ProjName -p com.compnyName.ProjName -l cpp
You should use cocos2d-console for creating project.
$ cocos2d-x-3.1.1/tools/cocos2d-console/bin/cocos new -d . -p com.example.testproject -l cpp TestProject

how to generate apk file using a command line?

please tell me how to build apk files of a project without the use of ECLIPSE ide. i found some infos about using a batch file but i don't know how to remake it.
echo on
SET PREV_PATH=%CD%
cd /d %0\..
REM Clear bin folder
rmdir "bin" /S /Q
rmdir "gen" /S /Q
mkdir "bin" || goto EXIT
mkdir "gen" || goto EXIT
REM Set your application name
SET APP_NAME=SecureSms
REM Define minimal Android revision
SET ANDROID_REV=android-8
REM Define aapt add command
SET ANDROID_AAPT_ADD="%ANDROID-SDK%\platforms\%ANDROID_REV%\tools\aapt.exe" add
REM Define aapt pack and generate resources command
SET ANDROID_AAPT_PACK="%ANDROID-SDK%\platforms\%ANDROID_REV%\tools\aapt.exe" package -v -f -I "%ANDROID-SDK%\platforms\%ANDROID_REV%\android.jar"
REM Define class file generator command
SET ANDROID_DX="%ANDROID-SDK%\platform-tools\dx.bat" --dex
REM Define Java compiler command
SET JAVAC="%JAVABIN%\javac.exe" -classpath "%ANDROID-SDK%\platforms\%ANDROID_REV%\android.jar"
SET JAVAC_BUILD=%JAVAC% -sourcepath "src;gen" -d "bin"
REM Generate R class and pack resources and assets into resources.ap_ file
call %ANDROID_AAPT_PACK% -M "AndroidManifest.xml" -A "assets" -S "res" -m -J "gen" -F "bin\resources.ap_" || goto EXIT
REM Compile sources. All *.class files will be put into the bin folder
call %JAVAC_BUILD% src\org\secure\sms\*.java || goto EXIT
REM Generate dex files with compiled Java classes
call %ANDROID_DX% --output="%CD%\bin\classes.dex" %CD%\bin || goto EXIT
REM Recources file need to be copied. This is needed for signing.
copy "%CD%\bin\resources.ap_" "%CD%\bin\%APP_NAME%.ap_" || goto EXIT
REM Add generated classes.dex file into application package
call %ANDROID_AAPT_ADD% "%CD%\bin\%APP_NAME%.ap_" "%CD%\bin\classes.dex" || goto EXIT
REM Create signed Android application from *.ap_ file. Output and Input files must be different.
call "%JAVABIN%\jarsigner" -keystore "%CD%\keystore\my-release-key.keystore" -storepass "password" -keypass "password" -signedjar "%CD%\bin\%APP_NAME%.apk" "%CD%\bin\%APP_NAME%.ap_" "alias_name" || goto EXIT
REM Delete temp file
del "bin\%APP_NAME%.ap_"
:EXIT
cd "%PREV_PATH%"
ENDLOCAL
exit /b %ERRORLEVEL%
i got this codes from a site. (http://www.apriorit.com/our-company/dev-blog/233-how-to-build-apk-file-from-command-line)
i downloaded the source code sample and opened the batch file in there but it didn't generate it's apk file. usually the apk file is located at its bin\ right? but when i opened the folder, the file is not in there. please help me how to use this one. i'd appreciate you help.
You’ll have to have Apache ant for this one:
ant debug
This will build and sign the necessary .apk files.
For more info, please see this: http://codeseekah.com/2012/02/09/command-line-android-development-basics/
EDIT:
ant is not a part of standard Android SDK setup. You'll have to install it.
Download the latest ant zip file from The Apache Ant Project.
Extract the zip file to a folder, say c:\ant\
Add c:\ant to your path environment variable
Once these are done, you'll be able to run ant from the command line
The apk by default is located under bin and this is correct, but when you distribute source code it's better to not add any apk because a "fresh" compiled apk is always a better solution.
if you have a file called build.xml in the root of your project just do
ant debug
otherwise you need to update your project with the minimum informations required for the building phase with
android update project -t android-10 -p .
in this case android-10 is a target for your apk/app/api and you can customize this option for your targeted device.
After this you get your build.xml and everything is in place for generating an apk.
ant debug install
is actually viable if you create project with (note that you should specify the virtual device with "adb -s" command while installing if you're running multiple devices)
android create project -n <project_name>
-t <target_version> -p <path> -k <package> -a <activity>
and use this command to run on the avd (if you've started one)
adb -e shell "am start -a android.intent.action.MAIN -n com.your.package/.YourActivity"
(change -e option to -d if you're running on devices)
reference
better use "AVD Manager.exe" to start a virtual device if you don't know those command or parameters, as there're quite a lot.
One of the best example I found on Internet for creating Android APK is https://geosoft.no/development/android.html.Also you can use assembleDebug command in root directory (make sure setting gradle as environment variable), if you are using Gradle.

Categories

Resources