我使用的是Android Studio 1.0.2.当我在gradle任务中单击assembleRelease时,会生成两个文件,app-release-unaligned.apk和app-release.apk.我知道app-release-unaligned.apk是不对齐的,但app-release.apk是什么?是对齐apk吗?我的build.gradle如下所示.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
signingConfig signingConfigs.config
zipAlignEnabled true // Is this necessary or not in Android Studio 1.0.2?
}
}
Run Code Online (Sandbox Code Playgroud)
即使我没有将zipAlignEnabled设为true,也会生成app-release.apk.Android Studio 1.0.2中仍然需要它吗?我获得的有关zipalign的所有信息都是在Android Studio 1.0发布之前.
我已经找到了几个问题,但没有答案,所以这里希望有人可能有一些见解.当我尝试交换相机时,我调用下面的swapCamera功能.然而,相机预览只是冻结(虽然只是实时相机预览,应用程序不会冻结).
当我第一次打开应用程序时,一切正常.但是我注意到一些有趣的事 当我注销_surfaceHolder对象的memoryaddress(即我的SurfaceHolder对象)时,它给了我一个值,但每当我在应用程序完成启动后查询该值时,该内存地址都已更改.
更进一步,当我换掉相机时它给我的错误是非常令人困惑的.我在将它传递给摄像机之前注销了_surfaceHolder, _camera.setPreviewDisplay(_surfaceHolder);
并且在传入之前它不是null.
任何帮助是极大的赞赏.
我注意到了一些有趣的行为
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
{
private SurfaceHolder _surfaceHolder;
private Camera _camera;
boolean _isBackFacing;
public CameraPreview(Context context, Camera camera) {
super(context);
_camera = camera;
_isBackFacing = true;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
_surfaceHolder = getHolder();
_surfaceHolder.addCallback(this);
}
void refreshCamera()
{
try {
_camera.setPreviewDisplay(_surfaceHolder);
_camera.startPreview();
} catch (IOException e) {
Log.d("iCamera", "Error setting camera preview: " + e.getMessage());
} …Run Code Online (Sandbox Code Playgroud) 我的代码中有一行标记为黄色:
getSupportActionBar().setDisplayShowHomeEnabled(true);
Run Code Online (Sandbox Code Playgroud)
安装appcompat-v7:22.1后, 它显示了一个提示:
"方法调用可能会产生java.lang.nullpointerexception".
应该用什么来代替getSupportActionBar()?
我希望repositories我在buildscript.repositories块中指定的与依赖项repositories块的存储库相同。请看我的例子:
buidldscript:buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:2.1.2"
}
}
repositories {
jcenter()
}
Run Code Online (Sandbox Code Playgroud)
我该如何做类似以下的事情?
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:2.1.2"
}
}
repositories = buildscript.repositories
Run Code Online (Sandbox Code Playgroud) 以下代码不使用clang ++ 3.8.0和g ++ 6.3.0(编译器标志-std=c++11 -Wall -Wextra -Werror -pedantic-errors)编译:
int main()
{
int* a = int*{}; // doesn't compile
// ^^^^ can't be parsed as a type
(void)a;
using PInt = int*;
PInt b = PInt{}; // compiles successfully
// ^^^^ is parsed as a type
(void)b;
}
Run Code Online (Sandbox Code Playgroud)
它是一种强制int*{}编译器以正确的方式在这里解释(typedef荷兰国际集团的int*是这样的一种方式)?
我正在用 Robolectric 测试我的 android 应用程序,但我正在努力解决这个问题:
MyModel myModel = ((MyApplication) context.getApplicationContext()).getMyModel;
Run Code Online (Sandbox Code Playgroud)
显然 Robolectric 抱怨这个错误:
java.lang.RuntimeException: java.lang.ClassCastException: android.app.Application cannot be cast to com.reply.delhaize.common.DelhaizeApplication
at org.robolectric.util.SimpleFuture.run(SimpleFuture.java:57)
at org.robolectric.shadows.ShadowAsyncTask$2.run(ShadowAsyncTask.java:95)
at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:37)
at org.robolectric.util.Scheduler.post(Scheduler.java:42)
at org.robolectric.shadows.ShadowAsyncTask.execute(ShadowAsyncTask.java:92)
at android.os.AsyncTask.execute(AsyncTask.java)
at com.reply.delhaize.common.models.StoreModel.getStoreList(StoreModel.java:617)
at com.reply.delhaize.common.models.StoreModel.fetchAllStores(StoreModel.java:107)
at com.reply.delhaize.core.tests.storefinder.StoreFinderTest.fetchAllStoresWhenWifiIsOn(StoreFinderTest.java:84)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:234)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:175)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at …Run Code Online (Sandbox Code Playgroud) 我的应用程序根据应用程序中的选定语言设置区域设置 到Kitkat我的代码工作正常.更新到Lollipop后,未设置区域设置.在这里,我粘贴我的代码来设置区域设置..
Locale locale = new Locale("de_DE");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, null);
Run Code Online (Sandbox Code Playgroud) 嗨,人们刚接触Java并且进展缓慢.我在添加行和列之前尝试使用随机数填充2D数组.到目前为止,我可以创建数组,显示它,我很确定我有添加位排序.但是当我尝试用随机数填充它时,我得到了一个outofboundsexception.我哪里错了?
public static void main(String[] args)
{
//create the grid
final int row = 9;
final int col = 9;
int [][] grid = new int [row][col];
//fill the grid
for (int i=0; i<grid.length; i++)
grid[i][grid[i].length] = (int)(Math.random()*10);
//display output
for(int i=0;i<grid.length; i++)
{
for(int j=0; j<grid[i].length; j++)
System.out.print(grid[i][j]+"");
System.out.println();
}
int sum = 0;
for (int i = 0; i < grid.length; i++) {
System.out.println("This row sums up to: " + sum);
for (int j = 0; j < …Run Code Online (Sandbox Code Playgroud) 我正在使用适用于Android L'Toolbar-ActionBar的Android L v21支持库.我希望工具栏中的项目为白色.即导航后退按钮,操作按钮,溢出操作.如果我使用暗版本作为应用程序主题(Theme.AppCompat.NoActionBar),则所有工具栏项都以白色显示.但是当我为应用程序使用light版本(Theme.AppCompat.Light.NoActionBar)时,所有工具栏项都显示为黑色.我想使用灯光主题,并希望使工具栏显示为白色.
我已经使用activity.setTitleTextColor()来更改标题的文本颜色,但不知道如何更改其余的颜色.

解:
感谢@ianhanniballake
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
Run Code Online (Sandbox Code Playgroud) 通过向我的应用添加adMob横幅,我遇到了一个奇怪的问题.这是我第一次使用android studio,所以我跟着教程(唯一不同的是build.gradle文件的编辑).
我一如既往地为布局添加横幅:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_cut"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/banner" />
<com.google.android.gms.ads.AdView
android:id="@+id/banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/admob_id" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
并将横幅初始化为我的活动:
AdView mAdView = (AdView) findViewById(R.id.banner);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Run Code Online (Sandbox Code Playgroud)
现在,当我启动我的应用程序时,横幅空间是空的,我得到一些警告,如
W/Ads? Not enough space to show ad. Needs 360x50 dp, but only has 328x479 dp.
Run Code Online (Sandbox Code Playgroud)
但是日志告诉我横幅已正确加载:
I/Ads? Scheduling ad refresh 40000 milliseconds from now.
I/Ads? Ad finished loading.
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?
我有一个大小为 n 的数组。我需要找到具有给定数字的每个元素的 GCD,如果它大于 1,则将其添加到另一个数组中。这样做的最快方法是什么?
我试图实现循环缓冲区.所以现在我正在测试一些代码.
raw_buffer.h
#include <algorithm> // for std::min
#ifndef RAWBUFFER_H
#define RAWBUFFER_H
class CircularBuffer
{
public:
CircularBuffer(size_t capacity);
~CircularBuffer();
size_t size() const { return size_; }
size_t capacity() const { return capacity_; }
// Return number of bytes written.
size_t write(const char *data, size_t bytes);
// Return number of bytes read.
size_t read(char *data, size_t bytes);
private:
size_t beg_index_, end_index_, size_, capacity_;
char *data_;
};
extern CircularBuffer MyCircularBuffer;
#endif
Run Code Online (Sandbox Code Playgroud)
main_raw.cpp
#include "raw_buffer.h"
#include <iostream>
#include <string>
using namespace std;
int main() …Run Code Online (Sandbox Code Playgroud)