Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
2fdcb59f
Commit
2fdcb59f
authored
Mar 14, 2016
by
Jason Simmons
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2673 from jason-simmons/gradle_example
Example that builds a Flutter Android app using Gradle
parents
a9b7a41b
d9f66d9e
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
262 additions
and
0 deletions
+262
-0
README.md
examples/hello_android/README.md
+16
-0
build.gradle
examples/hello_android/app/build.gradle
+15
-0
main.dart
examples/hello_android/app/src/flutter/lib/main.dart
+7
-0
pubspec.yaml
examples/hello_android/app/src/flutter/pubspec.yaml
+4
-0
AndroidManifest.xml
examples/hello_android/app/src/main/AndroidManifest.xml
+25
-0
FlutterActivity.java
...pp/src/main/java/com/example/flutter/FlutterActivity.java
+39
-0
flutter_layout.xml
.../hello_android/app/src/main/res/layout/flutter_layout.xml
+18
-0
strings.xml
examples/hello_android/app/src/main/res/values/strings.xml
+5
-0
build.gradle
examples/hello_android/build.gradle
+17
-0
build.gradle
examples/hello_android/buildSrc/build.gradle
+7
-0
FlutterPlugin.groovy
...llo_android/buildSrc/src/main/groovy/FlutterPlugin.groovy
+107
-0
flutter.properties
...main/resources/META-INF/gradle-plugins/flutter.properties
+1
-0
settings.gradle
examples/hello_android/settings.gradle
+1
-0
No files found.
examples/hello_android/README.md
0 → 100644
View file @
2fdcb59f
# Example of building a Flutter app for Android using Gradle
This project demonstrates how to embed Flutter within an Android application
and build the Android and Flutter components with Gradle.
To build this project:
*
Create a
`local.properties`
file with these entries:
*
`sdk.dir=[path to the Android SDK]`
*
`flutter.sdk=[path to the Flutter SDK]`
*
`flutter.jar=[path to the flutter.jar file in your build of the Flutter engine]`
Then run:
*
`gradle wrapper`
*
`./gradlew build`
examples/hello_android/app/build.gradle
0 → 100644
View file @
2fdcb59f
apply
plugin:
'com.android.application'
apply
plugin:
'flutter'
android
{
compileSdkVersion
22
buildToolsVersion
'22.0.1'
lintOptions
{
disable
'InvalidPackage'
}
}
flutter
{
source
'src/flutter'
}
examples/hello_android/app/src/flutter/lib/main.dart
0 → 100644
View file @
2fdcb59f
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/widgets.dart'
;
void
main
(
)
=>
runApp
(
new
Center
(
child:
new
Text
(
'Hello from Flutter!'
)));
examples/hello_android/app/src/flutter/pubspec.yaml
0 → 100644
View file @
2fdcb59f
name
:
gradle
dependencies
:
flutter
:
path
:
../../../../../packages/flutter
examples/hello_android/app/src/main/AndroidManifest.xml
0 → 100644
View file @
2fdcb59f
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"com.example.flutter"
android:versionCode=
"1"
android:versionName=
"1.0.0"
>
<uses-sdk
android:minSdkVersion=
"16"
android:targetSdkVersion=
"21"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<application
android:name=
"org.domokit.sky.shell.SkyApplication"
android:label=
"@string/app_name"
>
<activity
android:name=
".FlutterActivity"
android:label=
"@string/app_name"
android:configChanges=
"orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:launchMode=
"singleTask"
android:theme=
"@android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode=
"adjustResize"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
examples/hello_android/app/src/main/java/com/example/flutter/FlutterActivity.java
0 → 100644
View file @
2fdcb59f
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package
com
.
example
.
flutter
;
import
android.app.Activity
;
import
android.os.Bundle
;
import
org.chromium.base.PathUtils
;
import
org.domokit.sky.shell.SkyApplication
;
import
org.domokit.sky.shell.SkyMain
;
import
org.domokit.sky.shell.PlatformViewAndroid
;
import
java.io.File
;
public
class
FlutterActivity
extends
Activity
{
private
PlatformViewAndroid
flutterView
;
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
SkyMain
.
ensureInitialized
(
getApplicationContext
(),
null
);
setContentView
(
R
.
layout
.
flutter_layout
);
flutterView
=
(
PlatformViewAndroid
)
findViewById
(
R
.
id
.
flutter_view
);
File
appBundle
=
new
File
(
PathUtils
.
getDataDirectory
(
this
),
SkyApplication
.
APP_BUNDLE
);
flutterView
.
runFromBundle
(
appBundle
.
getPath
(),
null
);
}
@Override
protected
void
onDestroy
()
{
if
(
flutterView
!=
null
)
{
flutterView
.
destroy
();
}
super
.
onDestroy
();
}
}
examples/hello_android/app/src/main/res/layout/flutter_layout.xml
0 → 100644
View file @
2fdcb59f
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
>
<TextView
android:id=
"@+id/text_view"
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/title"
/>
<org.domokit.sky.shell.PlatformViewAndroid
android:id=
"@+id/flutter_view"
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
/>
</LinearLayout>
examples/hello_android/app/src/main/res/values/strings.xml
0 → 100644
View file @
2fdcb59f
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name=
"app_name"
>
Flutter App
</string>
<string
name=
"title"
>
Flutter Application
</string>
</resources>
examples/hello_android/build.gradle
0 → 100644
View file @
2fdcb59f
buildscript
{
repositories
{
jcenter
()
}
dependencies
{
classpath
'com.android.tools.build:gradle:1.5.0'
}
}
task
clean
(
type:
Delete
)
{
delete
rootProject
.
buildDir
}
task
wrapper
(
type:
Wrapper
)
{
gradleVersion
=
'2.8'
}
examples/hello_android/buildSrc/build.gradle
0 → 100644
View file @
2fdcb59f
repositories
{
jcenter
()
}
dependencies
{
compile
"com.android.tools.build:gradle:1.5.0"
}
examples/hello_android/buildSrc/src/main/groovy/FlutterPlugin.groovy
0 → 100644
View file @
2fdcb59f
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package
org.domokit.sky.gradle
import
com.android.builder.model.AndroidProject
import
org.gradle.api.DefaultTask
import
org.gradle.api.GradleException
import
org.gradle.api.Project
import
org.gradle.api.Plugin
import
org.gradle.api.Task
import
org.gradle.api.file.FileCollection
import
org.gradle.api.tasks.Copy
import
org.gradle.api.tasks.InputDirectory
import
org.gradle.api.tasks.OutputDirectory
import
org.gradle.api.tasks.TaskAction
class
FlutterPlugin
implements
Plugin
<
Project
>
{
private
File
sdkDir
@Override
void
apply
(
Project
project
)
{
Properties
properties
=
new
Properties
()
properties
.
load
(
project
.
rootProject
.
file
(
"local.properties"
).
newDataInputStream
())
String
enginePath
=
properties
.
getProperty
(
"flutter.jar"
)
if
(
enginePath
==
null
)
{
throw
new
GradleException
(
"flutter.jar must be defined in local.properties"
)
}
FileCollection
flutterEngine
=
project
.
files
(
enginePath
)
if
(!
flutterEngine
.
singleFile
.
isFile
())
{
throw
new
GradleException
(
"flutter.jar must point to a Flutter engine JAR"
)
}
String
sdkPath
=
properties
.
getProperty
(
"flutter.sdk"
)
if
(
sdkPath
==
null
)
{
throw
new
GradleException
(
"flutter.sdk must be defined in local.properties"
)
}
sdkDir
=
project
.
file
(
sdkPath
)
if
(!
sdkDir
.
isDirectory
())
{
throw
new
GradleException
(
"flutter.sdk must point to the Flutter SDK directory"
)
}
project
.
extensions
.
create
(
"flutter"
,
FlutterExtension
)
project
.
dependencies
.
add
(
"compile"
,
flutterEngine
)
project
.
afterEvaluate
this
.&
addFlutterTask
}
private
void
addFlutterTask
(
Project
project
)
{
if
(
project
.
flutter
.
source
==
null
)
{
throw
new
GradleException
(
"Must provide Flutter source directory"
)
}
FlutterTask
flutterTask
=
project
.
tasks
.
create
(
"flutterBuild"
,
FlutterTask
)
{
sdkDir
this
.
sdkDir
sourceDir
project
.
file
(
project
.
flutter
.
source
)
intermediateDir
project
.
file
(
"${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/flutter"
)
}
project
.
android
.
applicationVariants
.
all
{
variant
->
Task
copyFlxTask
=
project
.
tasks
.
create
(
name:
"copyFlx${variant.name.capitalize()}"
,
type:
Copy
)
{
dependsOn
flutterTask
dependsOn
variant
.
mergeAssets
from
flutterTask
.
flxPath
into
variant
.
mergeAssets
.
outputDir
}
variant
.
outputs
[
0
].
processResources
.
dependsOn
(
copyFlxTask
)
}
}
}
class
FlutterExtension
{
String
source
}
class
FlutterTask
extends
DefaultTask
{
File
sdkDir
@InputDirectory
File
sourceDir
@OutputDirectory
File
intermediateDir
String
getFlxPath
()
{
return
"${intermediateDir}/app.flx"
}
@TaskAction
void
build
()
{
if
(!
sourceDir
.
isDirectory
())
{
throw
new
GradleException
(
"Invalid Flutter source directory: ${sourceDir}"
)
}
intermediateDir
.
mkdirs
()
project
.
exec
{
executable
"${sdkDir}/bin/flutter"
workingDir
sourceDir
args
"build"
args
"-o"
,
flxPath
args
"--snapshot"
,
"${intermediateDir}/snapshot_blob.bin"
args
"--depfile"
,
"${intermediateDir}/snapshot_blob.bin.d"
args
"--working-dir"
,
"${intermediateDir}/flx"
}
}
}
examples/hello_android/buildSrc/src/main/resources/META-INF/gradle-plugins/flutter.properties
0 → 100644
View file @
2fdcb59f
implementation-class
=
org.domokit.sky.gradle.FlutterPlugin
examples/hello_android/settings.gradle
0 → 100644
View file @
2fdcb59f
include
':app'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment