Don't Compile and Run APK with Android Module Wizard
lazarus / 43-Android
----------------------------------------------------------------------
developing · 2015-07-18 08:57
Hi all
I use install_tutorial_eclipse_users.txt file to setup and configure
Lazarus IDE.
All things OK.
I install Eclipse for Mobile Developers Version: Juno Service Release
2,
install ADT Bundle ver: 23.0.6.1720515,
Laz4android,
Android Module Wizard Version 0.6 - rev. 20 - 07 April 2015,
NDK r10,
Apache Ant ver.1.9.2 ,
JDK ver 1.8.0.31,
install and update SDK
Create an android project in eclipse like tutorial and import this
into Lazarus IDE truly. Then put a "jTextView" component on form and
Build that. Project compiled successfully.
When I use "Run--> [Lamw] Build and Run" menu to create APK Build
error and show below message:
Code: [Select]Building APK... : Exit code 1, Errors: 1
Buildfile: H:\Projects\Eclipse\workspace\Demo\build.xml
-set-mode-check:
-set-debug-files:
-check-env:
[checkenv] Android SDK Tools Revision 24.0.2
[checkenv] Installed at F:\android-sdk
-setup:
[echo] Project Name: Demo
[gettype] Project Type: Application
-set-debug-mode:
-debug-obfuscation-check:
-pre-build:
-build-setup:
[getbuildtools] Using latest Build Tools: 19.1.0
[echo] Resolving Build Target for Demo...
[gettarget] Project Target: Android 4.1.2
[gettarget] API level: 16
[echo] ----------
[echo] Creating output directories if needed...
[mkdir] Created dir: H:\Projects\Eclipse\workspace\Demo\bin\rsObj
[mkdir] Created dir: H:\Projects\Eclipse\workspace\Demo\bin\rsLibs
[echo] ----------
[echo] Resolving Dependencies for Demo...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency]
[dependency] ------------------
[echo] ----------
[echo] Building Libraries with 'debug'...
[subant] No sub-builds to iterate on
-code-gen:
[mergemanifest] Found Deleted Target File
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
[aidl] No AIDL files to compile.
[echo] ----------
[echo] Handling RenderScript files...
[echo] ----------
[echo] Handling Resources...
[aapt] Generating resource IDs...
[aapt]
H:\Projects\Eclipse\workspace\Demo\res\values\styles.xml:7: error:
Error retrieving parent for item: No resource found that matches the
given name 'Theme.AppCompat.Light'.
[aapt]
H:\Projects\Eclipse\workspace\Demo\res\values-v11\styles.xml:7: error:
Error retrieving parent for item: No resource found that matches the
given name 'Theme.AppCompat.Light'.
[aapt]
H:\Projects\Eclipse\workspace\Demo\res\values-v14\styles.xml:8: error:
Error retrieving parent for item: No resource found that matches the
given name 'Theme.AppCompat.Light.DarkActionBar'.
BUILD FAILED
F:\android-sdk\tools\ant\build.xml:653: The following error occurred
while executing this line:
F:\android-sdk\tools\ant\build.xml:698: null returned: 1
Total time: 5 seconds
Panic: tool stopped with exit code 1. Use context menu to get more
information.
Exception, Errors: 1
Fatal: [Exception] Failed: Cannot build APK!
Any solution?
----------------------------------------------------------------------
jmpessoa · 2015-07-23 00:45
Hi developing!
Try change project "AndroidManifest.xml" according your system
installation....
change here:
Code: [Select]
try other: "android:targetSdkVersion" [18 or 19 or 20 or 21 or 22]
It depends on what you system have installed!
Thank you!
Ps.
Remember: Eclipse is not mandatory... please, read
"install_tutorial_Ant_users.txt", too.
----------------------------------------------------------------------
developing · 2015-07-23 18:08
Hi
Thanks to Your answer.
I read install_tutorial_ant_users.txt and follow this tutorial, but
show that error again.
Even I want use some demos to change and build, but this way doesn't
any solution and show an error (in attached picture).
I use eclipse and create APK file easily. but cannot create an APK
with lazarus yet.
I attach F:\android-sdk\tools\ant\build.xml file that has error for
any solution.
----------------------------------------------------------------------
jmpessoa · 2015-07-23 23:11
Hello developing!
Please,
1.
Put here your "JNIAndroidProject.ini" [ ...\laz4android\config ]
2.
You can change your project "bulid.xml" [NOT Ant 'bulid.xml" !!!]
Code: [Select]
Try the same "target" from your "AndroidManifest.xml"
Change here:
Code: [Select]
and here for Demo
Code: [Select]
3. If you have an eclipse project, then you can try use it to
build/run your Apk!
Your Project --->>Run As ---> Android Application
4. Note: From Lazarus you need "Run" ---> "Build" to get your
"controls.so" ...
and then "refresh" your eclipse project ... before run it ...
----------------------------------------------------------------------
developing · 2015-08-03 07:15
Hi,
Sorry for late to reply.
My project "build.xml" and Laz4Android "JNIAndroidProject.ini"
attached.
I cannot build APK in Lazarus yet, and error that write in first post
existence. For deploy and build APK use Eclipse IDE.
When design project in lazarus, layout is OK, but when "Run As --->
Android Application " in Eclipse and install output APK on a real
android device (Samsung Galaxy S3) "jTextView"s, "jEditText"s, and
"jButton"s are tumble like attached picture (after).
Pictures description:
before.jpg => That's mean before refresh project in Eclipse IDE
(Design time in Lazarus IDE).
after.jpg => That's mean after refresh and build project in Eclipse
IDE, then back to Lazarus IDE.
note1: I changed margins property (bottom, top) for all of components,
but this problem not solved.
note2: I changed "PosRelativeToAnchor" and "PosRelativeToParent"
property, but this problem don't solved.
And a suggestion, for Right to left language like Persian, Arabic and
Hebrew Add a BiDiMode property to change text directional like
Standard Edit component.
Thanks.
----------------------------------------------------------------------
developing · 2015-08-03 07:57
Hi,
I even change Top property of components (Like below), but don't solve
my problem and components keep their first position.
Code: [Select]jButton3. Top := jButton3. Top + 50;
Thanks.
----------------------------------------------------------------------
jmpessoa · 2015-08-04 22:19
Hello Developing!
What you need is do layouting based on "Anchor" and
"PosRelativeToParent" and "PosRelativeToAnchor"
and dimension based on "LayoutParamHeight" and "LayoutParamWhidth"
[Top, Left, Whidth and Height ... etc [just designer vision], does not
work on android "relative layout" model ...]
Edited: put here a "print screen" [what you want to accomplish]. I
will do a layout example code!
----------------------------------------------------------------------
developing · 2015-08-05 05:53
Hi
Thanks to reply.
I want create a project that to show in device same design time. In
the other words, I want my project components stay in design time
places. Or is it possible change top, left, right and bottom of any
components and my project layout in APK show like it in design layout?
For example: in real Android device like "before.jpg" picture "Save to
database" button to be top of components then under this "Full name"
label and etc like my design in this picture.
Thanks and sorry for my poor English.
----------------------------------------------------------------------
jmpessoa · 2015-08-05 13:37
Hello Devoloping!
Quote.... my project layout in APK show like it in design layout...
Yes! But you need a little more work!
You need do layouting based on "Anchor" and "PosRelativeToParent"
and "PosRelativeToAnchor" and dimension based on "LayoutParamHeight"
and "LayoutParamWhidth"
In Attachments you can see a "design time" picture and a "run time"
picture
Here is the code
"Unit1.pas"
Code: [Select]unit unit1;
{$mode delphi}
interface
uses
Classes, SysUtils, And_jni, And_jni_Bridge, Laz_And_Controls,
Laz_And_Controls_Events, AndroidWidget;
type
{ TAndroidModule1 }
TAndroidModule1 = class(jForm)
jButton1: jButton;
jButton2: jButton;
jEditText1: jEditText;
jEditText2: jEditText;
jListView1: jListView;
jTextView1: jTextView;
jTextView2: jTextView;
jTextView3: jTextView;
procedure jButton1Click(Sender: TObject);
private
{private declarations}
public
{public declarations}
end;
var
AndroidModule1: TAndroidModule1;
implementation
{$R *.lfm}
{ TAndroidModule1 }
procedure TAndroidModule1.jButton1Click(Sender: TObject);
begin
jListView1.Add('Name: '+jEditText1.Text);
jListView1.Add('Number: '+jEditText2.Text);
end;
end.
"Unit1.lfm"
Code: [Select]object AndroidModule1: TAndroidModule1
Left = 306
Top = 64
Width = 320
Height = 573
MarginLeft = 0
MarginTop = 0
MarginRight = 0
MarginBottom = 0
Text = 'AndroidModule1'
ActivityMode = actMain
BackgroundColor = colbrDefault
object jTextView1: jTextView
Left = 74
Top = 5
Width = 171
Height = 20
MarginLeft = 5
MarginTop = 5
MarginRight = 5
MarginBottom = 5
Visible = True
PosRelativeToAnchor = []
PosRelativeToParent = [rpTop, rpCenterHorizontal]
LayoutParamWidth = lpWrapContent
LayoutParamHeight = lpWrapContent
Text = 'App Developing Data Demo1'
Alignment = taLeft
Enabled = True
BackgroundColor = colbrDefault
FontColor = colbrDefault
FontSize = 0
TextTypeFace = tfNormal
FontSizeUnit = unitDefault
Id = 1827166
end
object jTextView2: jTextView
Left = 5
Top = 35
Width = 61
Height = 20
MarginLeft = 5
MarginTop = 5
MarginRight = 5
MarginBottom = 5
Visible = True
Anchor = jTextView1
PosRelativeToAnchor = [raBelow]
PosRelativeToParent = [rpLeft]
LayoutParamWidth = lpWrapContent
LayoutParamHeight = lpWrapContent
Text = 'Full Name:'
Alignment = taLeft
Enabled = True
BackgroundColor = colbrDefault
FontColor = colbrDefault
FontSize = 0
TextTypeFace = tfNormal
FontSizeUnit = unitDefault
Id = 8651431
end
object jEditText1: jEditText
Left = 5
Top = 70
Width = 310
Height = 39
MarginLeft = 5
MarginTop = 10
MarginRight = 5
MarginBottom = 10
Visible = True
Anchor = jTextView2
PosRelativeToAnchor = [raBelow]
PosRelativeToParent = []
LayoutParamWidth = lpMatchParent
LayoutParamHeight = lpWrapContent
Text = 'jEditText1'
Alignment = taLeft
InputTypeEx = itxText
MaxTextLength = -1
BackgroundColor = colbrDefault
FontColor = colbrDefault
FontSize = 0
HintTextColor = colbrSilver
ScrollBarStyle = scrNone
MaxLines = 1
HorScrollBar = True
VerScrollBar = True
WrappingLine = False
Editable = True
FontSizeUnit = unitDefault
Id = 8921191
end
object jTextView3: jTextView
Left = 5
Top = 124
Width = 99
Height = 20
MarginLeft = 5
MarginTop = 5
MarginRight = 5
MarginBottom = 5
Visible = True
Anchor = jEditText1
PosRelativeToAnchor = [raBelow]
PosRelativeToParent = [rpLeft]
LayoutParamWidth = lpWrapContent
LayoutParamHeight = lpWrapContent
Text = 'Contact Number:'
Alignment = taLeft
Enabled = True
BackgroundColor = colbrDefault
FontColor = colbrDefault
FontSize = 0
TextTypeFace = tfNormal
FontSizeUnit = unitDefault
Id = 2728698
end
object jEditText2: jEditText
Left = 5
Top = 159
Width = 146
Height = 39
MarginLeft = 5
MarginTop = 10
MarginRight = 5
MarginBottom = 10
Visible = True
Anchor = jTextView3
PosRelativeToAnchor = [raBelow]
PosRelativeToParent = [rpLeft]
LayoutParamWidth = lpHalfOfParent
LayoutParamHeight = lpWrapContent
Text = 'jEditText2'
Alignment = taLeft
InputTypeEx = itxText
MaxTextLength = -1
BackgroundColor = colbrDefault
FontColor = colbrDefault
FontSize = 0
HintTextColor = colbrSilver
ScrollBarStyle = scrNone
MaxLines = 1
HorScrollBar = True
VerScrollBar = True
WrappingLine = False
Editable = True
FontSizeUnit = unitDefault
Id = 7776822
end
object jButton1: jButton
Left = 172
Top = 153
Width = 146
Height = 40
MarginLeft = 2
MarginTop = 4
MarginRight = 2
MarginBottom = 4
Visible = True
Anchor = jTextView3
PosRelativeToAnchor = [raBelow]
PosRelativeToParent = [rpRight]
LayoutParamWidth = lpHalfOfParent
LayoutParamHeight = lpWrapContent
Text = 'Save Contact'
BackgroundColor = colbrDefault
FontColor = colbrDefault
FontSize = 0
FontSizeUnit = unitDefault
OnClick = jButton1Click
Id = 0
end
object jButton2: jButton
Left = 2
Top = 212
Width = 316
Height = 40
MarginLeft = 2
MarginTop = 4
MarginRight = 2
MarginBottom = 4
Visible = True
Anchor = jEditText2
PosRelativeToAnchor = [raBelow]
PosRelativeToParent = []
LayoutParamWidth = lpMatchParent
LayoutParamHeight = lpWrapContent
Text = 'Show Contacts'
BackgroundColor = colbrDefault
FontColor = colbrDefault
FontSize = 0
FontSizeUnit = unitDefault
Id = 4432728
end
object jListView1: jListView
Left = 7
Top = 263
Width = 305
Height = 96
Visible = True
Anchor = jButton2
PosRelativeToAnchor = [raBelow]
PosRelativeToParent = []
LayoutParamWidth = lpMatchParent
LayoutParamHeight = lpWrapContent
BackgroundColor = colbrDefault
FontColor = colbrDefault
FontSize = 0
WidgetItem = wgNone
Delimiter = '|'
TextDecorated = txtNormal
ItemLayout = layImageTextWidget
TextSizeDecorated = sdNone
TextAlign = alLeft
HighLightSelectedItemColor = colbrDefault
FontSizeUnit = unitDefault
Id = 0
end
end
Thank you!
----------------------------------------------------------------------
Leledumbo · 2015-08-05 15:11
Quote from: developing on August 05, 2015, 07:53:26 amOr is it
possible change top, left, right and bottom of any components and my
project layout in APK show like it in design layout?
Android does have AbsoluteLayout, but the default (and what LAMW
implements so far AFAICS) is to use RelativeLayout. This layout scales
very well with varying screen sizes instead of AbsoluteLayout which
might render your app elements invisible because it's located outside
the screen coordinates.
As it name says, RelativeLayout ignores absolute position (Top, Left)
and size (Width, Height) properties of a control.
----------------------------------------------------------------------
developing · 2015-08-07 14:00
Hi and thanks to all.
Finally I create first Android application only with use Lazarus and
"LAMW" (without Eclipse).
Your tutorial is good but for newbie like me:
After install "LAMW" packages, use this way:
1-In Lazarus IDE select "Project" -> "New Project" menu, then a window
shown,
2-from this window select "JNI Android Module [Lamw GUI]"
3-Press OK Button.
4-In "Android Module wizard", Enter a path on your H.D.D. into "Path
to workspace [project folder]" Field.(for example d:\Projects)
5-Enter a name for your project into "[Select] Eclipse Project or
[Enter] Ant Project Name:" field. (for example demo). This name is
your APK project name on Android.
6-Select your project Paltform, MinSdk and TargetApi. (for example
KitKat4.4, 16, 19)
7-Select Instruction and ARM Fpu. (for example ARMv7a and Soft)
8-Select Ant for Project Option, then press OK. If you select Eclipse
project don't create and Lazarus IDE crash.
9-Save unit1.pas in path that showed to you.
10-Now you can use "Run" -> "[Lamw] Build APK and run" menu in Lazarus
to create APK.
There was a point in my project that cannot Build APK with Lazarus:
Point: If you want use only lazarus for build APK project select Ant
from Project option.
But I had choose Eclipse.
A question: When we use this way, created APK is in debug mode. Is it
right? If this question is right, is there any way to create release
mode project?
----------------------------------------------------------------------
jmpessoa · 2015-08-07 16:41
Hi developing!
I will improve tutorial according yours advices!
Thany you!
Note: In "Revision 36" Ant and Eclipse projects were unifieds!!!
----------------------------------------------------------------------
A.S. · 2015-08-07 19:07
Quote from: developing on August 07, 2015, 04:00:20 pmA question: When
we use this way, created APK is in debug mode. Is it right? If this
question is right, is there any way to create release mode project?
For now "Build APK and Run" menu item builds APK in debug mode. You
can build APK in release mode manually but it should be signing:
to build in release mode check build-release.bat in your project
folder, for signing see
http://developer.android.com/tools/publishing/app-
signing.html#signing-manually
----------------------------------------------------------------------
jmpessoa · 2015-08-07 20:51
some more information:
In your project folder: "readme.txt" Item 13:
Quote. ...before to execute "build-release.bat [.sh]" you need
execute "release.keystore.bat [.sh]"! Please, read "readme-keytool-
input.txt!"
----------------------------------------------------------------------
developing · 2015-08-08 04:47
Hi and thanks,
For layout designing I write a simple topic for use newbies
programmers.
Question: How do we can design a custom layout that shown same in real
device?
Answer : You should use "Anchor", "PosRelativeToParent",
"PosRelativeToAnchor", "LayoutParamHeight", "LayoutParamWhidth"
property like below example.
Example:
1-Put a "jTextView" component on your "AndroidModule" form.
Set "PosRelativeToParent"
"rpCenterHorizontal" True
"rpTop" True
2-Put a "jButton" component on form.
Set "Anchor" to "jTextView" (Because you should set position
relative with "jTextView")
set "PosRelativeToAnchor"
"raBelow" True
3-Put a "jEditText" component on form.
Set "Anchor" to "jButton".
Set "PosRelativeToAnchor"
"raBelow" True.
and ...
Point: Anchor setting is most important section of this design,
because your component position depends on this property.
And for change width and/or height of each components you should
change "LayoutParamWhidth" and/or "LayoutParamHeight".
To design your layout follow this sample for any "jComponents".
Thanks.
Best regards.